I\'m using the code below to highlight some keywords in a text:
$message = str_ireplace($words,\'\'.$words.\'
Better code based on reply from @Savageman
$str = 'ba';
$highlightWhat = "ba";
$str = preg_replace_callback('#((?:(?!<[/a-z]).)*)([^>]*>|$)#si', function($m) use ($highlightWhat) {
return preg_replace('~('.$highlightWhat.')~i', '$1', $m[1]) . $m[2];
},
$str);