note 36612 added to function.str-replace
| From: | t at seebach dot dk | Date: | Thu, 16 Oct 2003 09:58:19 +0000 |
| Subject: | note 36612 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-58684@lists.php.net to get a copy of this message | ||
A simple way of making a case insensitive, multiple words (array) highligt of a string:
$needle = array("foo","bar","boo");
// use the | to make preg_replace to use multiple values
$needle = join('|',$needle);
// use the /i to make case insensitive and \\0 not replace th word but simply to wrap the word.
$text = preg_replace("/($needle)/i","<b>\\0</b>",$haystack);
Hope you can use it, enjoy Torben
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36612
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36612&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36612&report=yes
Search -- http://master.php.net/manage/user-notes.php