note 15365 deleted from function.str-replace by victor
| From: | victor@php.net | Date: | Sat, 09 Nov 2002 18:06:42 +0000 |
| Subject: | note 15365 deleted from function.str-replace by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-39226@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));
}
}