FIX-ed problem with highlighting second 'o' OR 'a', in this string
<?php
function highlight_string ($haystack, $needle, $highlight_class) {
$first_encode='XXXXXXXXXXXXXXX'; $second_encode='YYYYYYYYYYYYYYY';
preg_match_all("/$needle+/i", $haystack, $matches);
if (is_array($matches[0]) && count($matches[0]) >= 1) {
foreach ($matches[0] as $match) {
$haystack = str_replace($match, $first_encode.$match.$second_encode, $haystack);
}
}
$haystack=str_replace(array($first_encode,$second_encode),
array('<font class="'.$highlight_class.'" >','</font>'),$haystack);
return $haystack;
}
?>