php文件里搜索关键字,在PHP搜索脚本中突出显示关键字
簡單地說,你可以在這里調整循環:
$searchvar = trim($_GET['q']);
while ($row=mysql_fetch_assoc($searchResult)){
$description = str_replace($searchvar, ''.$searchvar."", $row['description']);
$results .="
{$row['title']}{$description}{$row['url']}";}為了使它更好一點:
$searchvar = explode(" ", trim($_GET['q'])); //puts each space separated word into the array.
while ($row=mysql_fetch_assoc($searchResult)){
$description = $row['description'];
foreach($searchvar as $var) $description = str_replace($var, ''.$var."", $description);
$description = str_replace($searchvar, ''.$searchvar."", $row['description']);
$results .="
{$row['title']}{$description}{$row['url']}";}第二個的好處是,如果用戶鍵入“ipod toudch yellow”,您將搜索“ipod”,“toudch”和“yellow”,這將否定類型并使結果更加通用。
你需要換單:
like '%query%'同
foreach(explode(" ", trim($_GET['q']) as $searchvar) $where[] = "like '%$searchvar%'";
$wheresql = implode(" OR ", $where);獲取每個搜索“word”以在sql中查找,或者您將使用不相關的突出顯示進行有限的搜索。
總結
以上是生活随笔為你收集整理的php文件里搜索关键字,在PHP搜索脚本中突出显示关键字的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle 数据泵使用——导入、导出
- 下一篇: 小程序 获取 用户 unionid