note 76585 deleted from function.str-ireplace by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 14:53:57 +0000 |
| Subject: | note 76585 deleted from function.str-ireplace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155682@lists.php.net to get a copy of this message | ||
Note Submitter: n00b at battleofthebits dot org
----
Dreamhost hasn't upgraded to PHP 5.0 -- I came up with my own alternative, trying to make it
run as much like str_ireplace() as possible. Adjust the switch-a-roo token if you think it may
conflict with your needle in teh haystack.
## HOMEBREW str_ireplace() FOR PRE-PHP 5.0
if (!function_exists('str_ireplace') {
function str_ireplace($search,$replace,$subject) {
$token = '^[[term^]';
$haystack = strtolower($subject);
$needle = strtolower($search);
while (($pos=strpos($haystack,$needle))!==FALSE) {
$c++;
$subject = substr_replace($subject,$token,$pos,strlen($search));
$haystack = substr_replace($haystack,$token,$pos,strlen($search));
}
while (($pos=strpos($subject,$token))!==FALSE) {
$subject = substr_replace($subject,$replace,$pos,strlen($token));
}
return $subject;
}
}