/ Published in: PHP
Highlight Search Terms in Text
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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 $text_string = str_replace($items[$y][0],'<span class="highlight">' . $items[$y][0] . '</span>',$text_string); } } } } return $text_string; }