Highlight search words in excerpt

Use str_replace to replace all occurances of the word to highlight with a around the word. Something like

// $searchresult = result of search process, 
//$highlightword = word you want to highlight
$searchresult = str_replace( $highlightword, 
     "<span style="background-color:#ffff00;">$highlightword</span>",
      $searchresult );

Adjust the background-color to what you want to use.

To limit the number of words in the search result, see the answer to a similar question: https://stackoverflow.com/questions/965235/how-can-i-truncate-a-string-to-the-first-20-words-in-php .

Edited: changed background color to yellow (#ffff00);