note 54978 deleted from function.str-ireplace by aidan
| From: | aidan@php.net | Date: | Sun, 24 Jul 2005 04:17:19 +0000 |
| Subject: | note 54978 deleted from function.str-ireplace by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-92358@lists.php.net to get a copy of this message | ||
Note Submitter: dazio at playable dot de
----
Lumpio- and Andrew got the fourth parameter of preg_replace wrong, which should not be count but
limit. Plus, $count needs to be a reference to make sense. So it comes down to this:
<?php
function str_ireplace($search, $replace, $subject, &$count) {
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, -1, $count);
}
?>
It would also be possible to add a $limit parameter with the default value -1.
Notice that it's not possible to make &$count optional. So if you don't want to use
it, you'll have to remove it.