note 93668 deleted from function.str-ireplace by danbrown
| From: | danbrown@php.net | Date: | Tue, 22 Sep 2009 14:41:06 +0000 |
| Subject: | note 93668 deleted from function.str-ireplace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160927@lists.php.net to get a copy of this message | ||
Note Submitter: mvdev
----
@ mvpetrovich
(php4 compatibility with new php5 functions)
The count param has been re-added to really be able to transport the code... still not working on
arrays but does the job!
Also added the check on $needle to avoid strpos exception if invalid char in search is entered (like
<)
<?php
function str_ireplace($search,$replace,$subject,&$count) {
$token = chr(1);
$haystack = strtolower($subject);
$needle = strtolower($search);
if (($needle===FALSE) || ($needle=='')) {
return $subject;
} else {
$count = 0;
while (($pos=strpos($haystack,$needle))!==FALSE) {
$subject = substr_replace($subject,$token,$pos,strlen($search));
$haystack = substr_replace($haystack,$token,$pos,strlen($search));
$count++;
}
$subject = str_replace($token,$replace,$subject);
return $subject;
}
}
?>