我正在使用此代码突出显示搜索关键字:
function highlightWords($string, $word)
{
$string = str_replace($word, "<span class='highlight'>".$word."</span>", $string);
/*** return the highlighted string ***/
return $string;
}
....
$cQuote = highlightWords(htmlspecialchars($row['cQuotes']), $search_result);
但是,这只突出显示了一个关键字。如果用户输入了多个关键字,它将缩小搜索范围,但不会突出显示任何单词。如何突出显示多个单词?