note 64455 added to function.eregi-replace
| From: | melissa at melissagirl dot com | Date: | Fri, 14 Apr 2006 16:28:57 +0000 |
| Subject: | note 64455 added to function.eregi-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-108091@lists.php.net to get a copy of this message | ||
Here's a nice case-insensitive highlight function that ignores any regular expression
characters and highlights a word and leaves it in whatever case it was before:
<?
function highlight($word, $subject) {
$regex_chars = '\.+?(){}[]^$';
for ($i=0; $i<strlen($regex_chars); $i++) {
$char = substr($regex_chars, $i, 1);
$word = str_replace($char, '\\'.$char, $word);
}
$word = '(.*)('.$word.')(.*)';
return eregi_replace($word, '\1<span
class="highlight">\2</span>\3', $subject);
}
?>
----
Server IP: 216.194.113.175
Probable Submitter: 71.39.3.166
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.eregi-replace.php
Edit -- http://master.php.net/note/edit/64455
Del: integrated -- http://master.php.net/note/delete/64455/integrated
Del: useless -- http://master.php.net/note/delete/64455/useless
Del: bad code -- http://master.php.net/note/delete/64455/bad+code
Del: spam -- http://master.php.net/note/delete/64455/spam
Del: non-english -- http://master.php.net/note/delete/64455/non-english
Del: in docs -- http://master.php.net/note/delete/64455/in+docs
Del: other reasons-- http://master.php.net/note/delete/64455
Reject -- http://master.php.net/note/reject/64455
Search -- http://master.php.net/manage/user-notes.php