/ Published in: PHP
Highlight Search Terms in Text
Expand |
Embed | Plain Text
function HighlightTerms($text_string,$keywords) { //this function searches for words from the keywords, and finds matches in the text, //and highlights (bolds) them. like google does. // $text_sting: the text from which you want to highlight and return... // $keywords: either string or array or words that should be highlighted in the text. //explode the keywords } //find matches for ($x=0;$x<count($keywords);$x++) { for ($y=0;$y<count($items);$y++) { $text_string = str_replace($items[$y][0],'<span class="highlight">' . $items[$y][0] . '</span>',$text_string); } } } } return $text_string; }
You need to login to post a comment.
