note 15365 added to function.str-replace
| From: | firewire at itsyourdomain dot com | Date: | Thu, 06 Sep 2001 19:56:05 +0000 |
| Subject: | note 15365 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-17740@lists.php.net to get a copy of this message | ||
My contribution to php a case insensitive search and replace.
function stri_replace($searchFor, $replaceWith, $string, $offset = 0) {
$lsearchFor = strtolower($searchFor);
$lstring = strtolower($string);
$newPos = strpos($lstring, $lsearchFor, $offset);
if (strlen($newPos) == 0) {
return($string);
} else{
$left = substr($string, 0, $newPos);
$right = substr($string, $newPos + strlen($searchFor));
$newStr = $left . $replaceWith . $right;
return stri_replace($searchFor, $replaceWith, $newStr, $newPos + strlen($replaceWith));
}
}
http://www.php.net/manual/en/function.str-replace.php