Can someone take a look at this highlight function? It works pretty good, but I'd like to know how to tweak it so that it:
1. highlights an entire phrase (it already does this)
2. highlights each individual word
3. does not mess up words inside <html> tags
1. highlights an entire phrase (it already does this)
2. highlights each individual word
3. does not mess up words inside <html> tags
Code:
function highlight($haystack,$needle){
$h = strtoupper($haystack);
$n = strtoupper($needle);
$pos = strpos($h,$n);
if ($pos !== false) {
$var = substr($haystack,0,$pos).'<span class="highlight"><strong>'.substr($haystack,$pos,strlen($needle)).'</strong></span>';
$var .= substr($haystack,($pos+strlen($needle)));
$haystack = $var;
}
return $haystack;
}