note 104676 added to function.str-ireplace
| From: | Psudo-thepsudo at gmail dot com | Date: | Thu, 30 Jun 2011 04:53:07 +0000 |
| Subject: | note 104676 added to function.str-ireplace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181084@lists.php.net to get a copy of this message | ||
For highlighting without the overhead of regex and without destroying capitalization, try this:
function highlight($needle, $haystack){
$ind = stripos($haystack, $needle);
$len = strlen($needle);
if($ind !== false){
return substr($haystack, 0, $ind) . "<b>" . substr($haystack, $ind, $len) .
"</b>" .
highlight($needle, substr($haystack, $ind + $len));
} else return $haystack;
}
This example uses HTML bold tags, but you can easily change the highlighting method.
----
Server IP: 69.147.83.197
Probable Submitter: 71.213.73.224
----
Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php
Edit -- https://master.php.net/note/edit/104676
Del: integrated -- https://master.php.net/note/delete/104676/integrated
Del: useless -- https://master.php.net/note/delete/104676/useless
Del: bad code -- https://master.php.net/note/delete/104676/bad+code
Del: spam -- https://master.php.net/note/delete/104676/spam
Del: non-english -- https://master.php.net/note/delete/104676/non-english
Del: in docs -- https://master.php.net/note/delete/104676/in+docs
Del: other reasons-- https://master.php.net/note/delete/104676
Reject -- https://master.php.net/note/reject/104676
Search -- https://master.php.net/manage/user-notes.php