highlight multiple keywords in search

Posted by fusion on Stack Overflow See other posts from Stack Overflow or by fusion
Published on 2010-05-03T11:02:48Z Indexed on 2010/05/03 11:08 UTC
Read the original article Hit count: 238

Filed under:
|
|
|
|

i'm using this code to highlight search keywords:

function highlightWords($string, $word)
 {

        $string = str_replace($word, "<span class='highlight'>".$word."</span>", $string);
    /*** return the highlighted string ***/
    return $string;

 }

 ....

  $cQuote =  highlightWords(htmlspecialchars($row['cQuotes']), $search_result);

however, this highlights only one keyword. if the user enters more than one keyword, it will narrow down the search but no word is highlighted. how can i highlight more than one word?

© Stack Overflow or respective owner

Related posts about php

Related posts about search