note 54406 added to function.str-ireplace
| From: | Lumpio- at osu1 dot php dot net | Date: | Sun, 03 Jul 2005 12:25:32 +0000 |
| Subject: | note 54406 added to function.str-ireplace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91349@lists.php.net to get a copy of this message | ||
The functions below seem to be missing preg_quote, which'll cause them to behave wrong if the
search string(s) have regex metacharacters in them. Fixed version below.
<?php
function str_ireplace($search, $replace, $subject, $count=null) {
if (is_array($search)) {
foreach ($search as $word) {
$words[] = "/".preg_quote($word, "/")."/i";
}
} else {
$words = "/".preg_quote($search, "/")."/i";
}
return preg_replace($words, $replace, $subject, $count);
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54406
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54406&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54406&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54406&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54406&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54406&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54406&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54406&report=yes
Search -- http://master.php.net/manage/user-notes.php