note 19184 added to function.str-replace
| From: | info at wmelchior dot com | Date: | Tue, 19 Feb 2002 09:31:55 +0000 |
| Subject: | note 19184 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-26780@lists.php.net to get a copy of this message | ||
dave's (dave@[nospam]netready.biz) solution for highlighting for non-case sensitive search
results works great with the exception that it leads to the unwanted result of also highlighting
html code if included with the $haystack.
So if you have :
$haystack = "I will break <b r> your heart";
(where <b r> should be the HTML line break)
and as search string
$needle = "br";
you get for:
echo highlight ( $needle, $haystack );
// "I will break [hilited]br[/hilited] your heart"
Simple solution (just for the sake of completeness , not a big deal):
1.) Remove ALL html or other formating code from $haystack
2.) Call
highlight ( $needle, $haystack );
3.) Replace $haystack with the highlighted version:
$haystack = highlight ($needle, $haystack);
4.) Do the html or other text conversions
like:
$haystack = str_replace("/n", "<b r>", $haystack);
5.)
echo $haystack;
Thanks again, Dave.
--
http://www.php.net/manual/en/function.str-replace.php
http://master.php.net/manage/user-notes.php?action=edit+19184
http://master.php.net/manage/user-notes.php?action=delete+19184
http://master.php.net/manage/user-notes.php?action=reject+19184