模糊查詢多條 高亮求 優化
?
==========拼接SQL 模糊查詢
foreach ($getPar as $key => $val){
? $searchVal.= "content LIKE '%{$val}%'";
? ?
? if($_count-1 >$key){
? ? $searchVal.="or ";
? }
? }?
--------------
//替換高亮 ? ? ?這里采用兩個循環 ,請問下 用一個循環怎么實現
?while ($row = mysql_fetch_assoc($rs)){
if($row['content']){?
foreach ($getPar as $key => $val){
$row['content']= str_replace($val, '<font color="red"><b>'.$val.'</b></font>',$row['content']);
}?
}
??
$user[] = $row;
?
}
2016-04-06
//關鍵詞數量
$num = count($getPar);
//替換添加
for($i=0;$<$num;$i++){
$replace[$i] = '<font color="red"><b>'.$val.'</b></font>';
}
//循環獲取
while ($row = mysql_fetch_assoc($rs)){
$row['content']= str_replace($getPar,$replace ,$row['content']);
$user[] = $row;
}