i'm using this code to highlight search keywords:
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);
however, this highlights only one keyword. if the user enters more than one keyword, it will narrow down the search but no word is highlighted. how can i highlight more than one word?
regular expressions is the way to go!
To match in a case-insensitive manner, add 'i' to the regular expression
NB: for non-enlish letters like "ä" the results may vary depending on the locale.
PHP > 5.3.0, try preg_filter()