note 90955 deleted from function.str-ireplace by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 14:45:38 +0000 |
| Subject: | note 90955 deleted from function.str-ireplace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155676@lists.php.net to get a copy of this message | ||
Note Submitter: robbiz233 at hotmail dot com
----
The post below me had a problem with the highlighting function, for example when highlighting
'getmor' on the string getmore. It would find the e as not highlighted but then attempt to
replace both e's in the string.
I thought i'd provide my attempt at a decent highlighting function.
function highlight($needle, $haystack)
{
$start = 0;
while(@stripos($haystack, $needle, $start) !== false)
{
$get = stripos($haystack, $needle, $start);
$get_text = substr($haystack, $get, strlen($needle));
$text_before = substr($haystack, 0, $get);
$text_after = substr($haystack, ($get+strlen($needle)));
$haystack = $text_before.'<font
color="red">'.$get_text.'</font>'.$text_after;
$start += ($get+strlen($needle)+25);
}
return $haystack;
}