Highlight | functions | show | Highlights such as: To retrieve ABC, the results show akjdfdkcdb, how to make the ABC display in red.
The functions are as follows:
function Highlight ($str, $keywords, $color = "Red") {
if (empty ($keywords)) {
return $str;
}
$keywords = Split ("[\t\r\n,]+", $keywords);
$str _begin = "##~~##~";
$str _end = "~##~~##";
foreach ($keywords as $val) {
$tvar = Preg_quote ($val);
$tvar = Str_replace ('/', ' \/', $tvar);
$patterns [] = "/(". $tvar. ")/";
$replacement [] = $str _begin. UrlEncode ($val). $str _end;
$tvar = Preg_quote (UrlEncode ($val));
$tvar = Str_replace ('/', ' \/', $tvar);
$tmppattern [] = "/(". $str _begin. $tvar. $str _end. ")/";
$finalrep [] = "<span style= ' color:". $color. "' > '. $val. "</span>";
}
$str = Preg_replace ($patterns, $replacement, $STR);
$str = Preg_replace ($tmppattern, $finalrep, $STR);
return $str;
}