note 23361 deleted from function.str-replace by victor
| From: | victor@php.net | Date: | Sat, 09 Nov 2002 18:10:15 +0000 |
| Subject: | note 23361 deleted from function.str-replace by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-39230@lists.php.net to get a copy of this message | ||
*** stri_replace function ***
I found this while searching on google. It works pretty well. Only drawback is that it makes the
string your searching for lowercase in the final result
ORIGINAL POST
"Author: Josh
Date: 2001-11-20 23:16:56
Subject: RE: A case-insensitive str_replace() ??
I had to figure this one out ;) I guess if you can not use any regular-expression compatible
replacement, this one should do the trick for you... Properly named stri_replace():
function stri_replace($replacer,$replacement,$string) {
$lowercase_replacer = strtolower($replacer);
// Make all the words we are replacing lowercase
$string = str_replace($replacer,$lowercase_replacer,$string);
// Replace all occurences
$string = str_replace($lowercase_replacer,$replacement,$string);
return $string;
}
It works exactly like str_replace() as far as arguments go. I tested this on PHP 4.2.0-dev incase
you have any problems (You shouldn't). Hope this helps.
-Josh B"
END ORIGINAL POST
-Chris