note 60830 deleted from function.str-ireplace by bjori
| From: | bjori@php.net | Date: | Mon, 10 Apr 2006 21:25:19 +0000 |
| Subject: | note 60830 deleted from function.str-ireplace by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-107727@lists.php.net to get a copy of this message | ||
Note Submitter: tmad4000 at gmail dot com
----
Here is a str_ireplace that works on servers running on lower than PHP 5 (4.4 is the lowest that it
will work on, I think). If you want it to be non-case-sensitive, remove the strtolower commands from
around $haystack and $needle.
<?php
//string insens_replace($haystack,$needle,$replacewith) - case insensitive replace function
function insens_replace($haystack,$needle,$replacewith)
{
static $recursed=FALSE;
static $beginpart='';
static $endpart='';
if(($pos=strpos(strtolower($haystack),strtolower($needle)))!==FALSE)
{
$recursed=TRUE;
$beginpart.=substr($haystack,0,$pos).$replacewith;
$endpart=substr($haystack,$pos+strlen($needle));
return insens_replace($endpart,$needle,$replacewith);
}
else
{
if($recursed)
{
$result=$beginpart.$endpart;
$recursed=FALSE;
$beginpart='';
$endpart='';
return $result;
}
else
{
return $haystack;
}
}
}
?>