Useful code to highlight text occurences in search results or in a text. How to highlight text in a string with PHP and regular expression? Here is the solution:
// highlight text in a string function highlight($text_highlight, $text_search) { $str = preg_replace('#'. preg_quote($text_highlight) .'#i', '<span style="background-color:#FFFF66; color:#FF0000;">\\0</span>', $text_search); return $str; }