note 52328 deleted from function.str-ireplace by aidan
| From: | aidan@php.net | Date: | Sun, 24 Jul 2005 04:17:38 +0000 |
| Subject: | note 52328 deleted from function.str-ireplace by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-92362@lists.php.net to get a copy of this message | ||
Note Submitter: php programmer at work
----
One more correction to the str_Ireplace function below: the strpos output should be compared against
false, otherwise needles in the beginning of haystacks will not be replaced:
function str_Ireplace($needle, $replacement, $haystack) {
$i = 0;
while (($pos = strpos(strtolower($haystack),
strtolower($needle), $i)) !== false) {
$haystack = substr($haystack, 0, $pos) . $replacement
. substr($haystack, $pos + strlen($needle));
$i = $pos + strlen($replacement);
}
return $haystack;
}