PHP
·
发表于 5年以前
·
阅读量:8305
±¾ÎÄʵÀý½²ÊoÁËphpʵÏÖscwsÖÐÎÄÖ´ÊËÑË÷µÄ½¨¡£ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼£¬¾ßÌaÈçÏ£º
1¡¢4¸oÎļþ£¨±¾Õ¾ÏÂÔصØÖ¡££(C)½aѹºo£¬Åµ½Ò»¸oµØ*½ eg:E:/wamp/scws
2¡¢php.ini ÖÐÅaÖÃ
extension = php_scws.dll
scws.default.charset = utf8 //ÅaÖÃĬÈϵıaÂe*½Ê½
scws.default.fpath = "E:/wamp/scws" //¼ÓѹºoÎļþµÄÂ*¾¶
3¡¢Ê¹ÓÃ
$so = scws_new();
$so->set_charset('utf8'); //±aÂe
// ÕaÀiûÓе÷Óà set_dict ºÍ set_rule ϵͳ»a×Ô¶¯ÊÔµ÷Óà ini ÖÐÖ¸¶¨Â*¾¶ÏµĴʵaºÍ¹aeÔoÎļþ
$so->add_dict(ini_get('scws.default.fpath') . '/dict.utf8.xdb');
//$so->add_dict('./dd.txt',SCWS_XDICT_TXT);
$so->set_rule(ini_get('scws.default.fpath') . '/rules.utf8.ini');
$so->set_duality(0); //É¢×Ö¶þÔª
$so->set_ignore(0); //ºoÂÔ±eµa*uºÅ
$so->set_multi(0);
$wd='ÒªËÑË÷µÄÄÚÈÝ';
$so->send_text($wd);
while($tmp = $so->get_result())
//±eÀuºo¼´µÃµ½×Ö*u´®*Ö¸iºoµÄÄÚÈÝ£¬
//¸u¾ÝµÃµ½µÄÄÚÈÝ*Ö±ðµ½Êý¾Ý¿aÖвeÕÒ£¨likeÆ¥Åa£(C)
{
}
Ç××ÔÊÔÑeÁËÒ»ÏÂÈçÏ£º
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
<body>
<?php
function search($keywords,$table,$key1,$key2){
// (Òª²eÕÒµÄ×Ö*u´®,±iÃu,×Ö¶ÎÒ»,×ֶζþ)Èç¹u¾ÍÒ»¸o×ֶεĻ°£¬$key2='';
$arr=array();
$str=array();
if( preg_match("/^[^\x80-\xff]+$/", $keywords)){//ÅжÏkeywordsÊÇ*ñȫΪӢÎÄ£¬È«ÎªÓ¢ÎĵĻ°°´ÕÕ×Ö*u´®Çиi´¦Ài
$str1=explode(' ',$keywords); //ÏÈ°´ÕÕ¿Õ¸ñÇиi
foreach($str1 as $key=>$value)
{
$str2=explode(',',$value); //£¬Çиi
foreach($str2 as $k=>$v)
{
$str3=explode('.',$v); //¡£Çиi
foreach($str3 as $kk=>$vv)
{
array_push($arr,$vv);//´¦ÀiÍeºo£¬*µ»ØÒ»¸oÊý×e
}
}
}
}else{//¶ÔÖÐÎĵÄ*Ö´Ê´¦Ài
$so = scws_new();
$so->set_charset('utf8');
// ÕaÀiûÓе÷Óà set_dict ºÍ set_rule ϵͳ»a×Ô¶¯ÊÔµ÷Óà ini ÖÐÖ¸¶¨Â*¾¶ÏµĴʵaºÍ¹aeÔoÎļþ
$so->add_dict(ini_get('scws.default.fpath') . '/dict.utf8.xdb');
$so->set_rule(ini_get('scws.default.fpath') . '/rules.utf8.ini');
$so->set_duality(0); //É¢×Ö¶þÔª
$so->set_ignore(0); //ºoÂÔ±eµa*uºÅ
$so->set_multi(0);
$so->send_text($keywords);
while ($tmp = $so->get_result())//µÃµ½Ò»¸oÊý×e£¬ÀiÃae°uº¬´Ê×eºÍ±eµa*uºÅ
{
foreach($tmp as $key=>$value)
{
$value=$value["word"];
if(preg_match("/^[Ò»-ý›]{6,21}$/", $value))//È¥³ý±eµa*uºÅ
{
array_push($arr,$value);
}
}
}
}
foreach($arr as $key=>$value)//±aÀuµÃµ½µÄÊý×e,µ½Êý¾Ý¿aÖÐÆ¥Åa
{
if($key2!='')
{
$sql="select * from `$table` where `$key1` like '%$value%' or `$key2` like '%$value%'";
}else{
$sql="select * from `$table` where `$key1` like '%$value%'";
}
$query=mysql_query($sql);
array_push($str,$query);
}
return $str;
}
include('conn.php');
$keywords="¹þ¹þlsd djk,hdjs dd";
$table='two_key';
$key1='address';
$key2='';
$query=search($keywords,$table,$key1,$key2);
foreach($query as $key=>$value)
{
while($row=mysql_fetch_array($value))
{
echo $row[id].'----'.$row[name].'-----'.$row[address].'<br>';
}
}
?>
</body>
</html>
Ï£Íu±¾ÎÄËuÊo¶Ô´o¼ÒPHP³ÌÐoÉe¼ÆÓÐËu°iÖu¡£