note 54406 deleted from function.str-ireplace by aidan
| From: | aidan@php.net | Date: | Sun, 24 Jul 2005 04:17:29 +0000 |
| Subject: | note 54406 deleted from function.str-ireplace by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-92360@lists.php.net to get a copy of this message | ||
Note Submitter: Lumpio-
----
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);
}
?>