From a user comment in php manual pages -
function highlight($needle, $haystack )
{
$parts = explode(strtolower($needle), strtolower($haystack));
$pos = 0;
foreach($parts as $key=>$part)
{
$parts[$key] = substr($haystack, $pos, strlen($part));
$pos += strlen($part);
$parts[$key] .= "<b>" . substr($haystack, $pos, strlen($needle)) . "</b>";
$pos += strlen($needle);
}
return implode('', $parts);
}
This function will highlight any occurrence of the search string ($needle) in text ($haystack), e.g. search for 'out' in 'without' results in 'without'.