私はこのコードを使用して検索キーワードを強調しています:
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);
ただし、これは1つのキーワードのみを強調表示します。ユーザーが複数のキーワードを入力すると、検索は絞り込まれますが、単語は強調表示されません。複数の単語を強調表示するにはどうすればよいですか?