There was a similar post topic quite recently, just with BB syntax instead. Try:
function highlight($string, $term)
{
return preg_replace("/(?<!\<)(\b{$term}\b)(?!\>)/i", '<span style="color:#f00;">\\1</span>', $string);
}
blocblue
Practically a Posting Shark
837 posts since Jan 2008
Reputation Points: 272
Solved Threads: 161
Skill Endorsements: 13
Hmm... after a little more searching, I came across another regex here.
$string = 'The PHP development team revit would like to announce the immediate availability of a new PHP version. The PDT project provides a PHP <img src="Images/Revit-Icon.jpg"> Development Tools framework for the Eclipse platform. PHP is especially suited for Web development and can be embedded into HTML. There are many development tools for PHP.';
echo highlight($string, 'revit');
/**
* Find and replace search term in specified string with highlight syntax.
*
* @param string $string
* @param string $term
* @return string
*/
function highlight($string, $term)
{
return preg_replace("/({$term})(?!([^<]+)?>)/i", '<span style="color:#f00;">\\1</span>', $string);
}
blocblue
Practically a Posting Shark
837 posts since Jan 2008
Reputation Points: 272
Solved Threads: 161
Skill Endorsements: 13