I do not have a PHP solution, but I suggest you do this on the client side. This means that you can cache any output server side and save several loops :)
Disclaimer . This is my own project.
searchTermsHighlight, jQuery. . , .
, PHP, stri_replace(), , . , , .
$searchTerms = array('war');
foreach($searchTerms as $term) {
$content = stri_replace($term, '<span class="highlight">' . $term . '</strong>', $content);
}
stri_replace(), .