note 32512 deleted from function.str-replace by aidan
| From: | aidan@php.net | Date: | Fri, 25 Jun 2004 06:06:57 +0000 |
| Subject: | note 32512 deleted from function.str-replace by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71641@lists.php.net to get a copy of this message | ||
Note Submitter: bradhuizenga at softhome dot net
----
This stri_replace() function is similar to the one above, except it accepts a $replace array if
given one, like str_replace. If the $find array is bigger than the $replace array, it will probably
nullify anything it finds without a corresponding item in the $replace array. If the $replace array
is larger than the $find array, the extra items in the $replace array will be ignored.
function stri_replace($find,$replace,$string)
{
if(!is_array($find)) $find = array($find);
if(!is_array($replace)) $replace = array($replace);
foreach($find as $fKey => $fItem)
{
$between = explode(strtolower($fItem),strtolower($string));
$pos = 0;
foreach($between as $bKey => $bItem)
{
$between[$bKey] = substr($string,$pos,strlen($bItem));
$pos += strlen($bItem) + strlen($fItem);
}
$string = implode($replace[$fKey],$between);
}
return($string);
}
Sorry for spaced tabbing.
- Brad Huizenga