rendered paste bodyfunction highlight_words($subject,$search)
{
$info = explode(" ", $search);
$count = substr_count($search, ' ');
if($count == '0') { $total="1"; } else { $total = $count + 1; }
$i=0;
$final_results="";
while($i <= $total)
{
$hlstart = "<strong>";
$hlend = "</strong>";
$srchlen=strlen($info[$i]);
if ($srchlen==0) return $subject;
$find = $subject;
while($find = stristr($find,$info[$i]))
{
$srchtxt = substr($find, 0, $srchlen);
$find=substr($find,$srchlen);
$subject = str_replace($srchtxt,"$hlstart$srchtxt$hlend",$subject);
}
$final_results="$subject";
// return $subject;
$i++;
}
return $final_results;
}
//one func
//other func
function highlight_words($text, $needle, $options = null, $highlight = null)
{
// Default highlighting
if ($highlight === null) {
$highlight = '<strong>\1</strong>';
}
// Select pattern to use
if ($options & STR_HIGHLIGHT_SIMPLE) {
$pattern = '#(%s)#';
$sl_pattern = '#(%s)#';
} else {
$pattern = '#(?!<.*?)(%s)(?![^<>]*?>)#';
$sl_pattern = '#<a\s(?:.*?)>(%s)</a>#';
}
// Case sensitivity
if (!($options & STR_HIGHLIGHT_CASESENS)) {
$pattern .= 'i';
$sl_pattern .= 'i';
}
$needle = (array) $needle;
foreach ($needle as $needle_s) {
$needle_s = preg_quote($needle_s);
// Escape needle with optional whole word check
if ($options & STR_HIGHLIGHT_WHOLEWD) {
$needle_s = '\b' . $needle_s . '\b';
}
// Strip links
if ($options & STR_HIGHLIGHT_STRIPLINKS) {
$sl_regex = sprintf($sl_pattern, $needle_s);
$text = preg_replace($sl_regex, '\1', $text);
}
$regex = sprintf($pattern, $needle_s);
$text = preg_replace($regex, $highlight, $text);
}
return $text;
}