note 32512 added to function.str-replace
| From: | bradhuizenga at rack1 dot php dot net | Date: | Thu, 29 May 2003 20:59:23 +0000 |
| Subject: | note 32512 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-49311@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32512
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32512&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32512&report=yes