Edit: hah. vim at least thinks it's valid.
When was str_ireplace() added?
Moderator: General Moderators
When was str_ireplace() added?
I have 4.3.11 and I'm getting 'call to undefined function' when I try to use it.
Edit: hah. vim at least thinks it's valid.
Edit: hah. vim at least thinks it's valid.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
str_ireplace() wrote:str_ireplace
(PHP 5)
str_ireplace -- Case-insensitive version of str_replace().
i would like to use this function ;( but my paid hosting has 4.3.11 as well
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
I like this method more than regex'n it...
I saw this code somewhere else, but I don't remember where. I'll just type it up again.
If you're jumping back and forth between a PHP 5 and a PHP 4 server, throw some sort of !function_exists block around it so that it is only defined if the function doesn't already exist.
- Nathaniel
I saw this code somewhere else, but I don't remember where. I'll just type it up again.
Code: Select all
function str_ireplace($search, $replace, $subject) //ignore count parameter, we obviously don't have PHP 5
{
return str_replace ( strlower($search), strlower($replace), strlower($search) );
}- Nathaniel
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
too bad that forces the output to be lower case...
untested..
of course, you could use the PHP Compatibility library from Pear: http://pear.php.net/package/PHP_Compat
Code: Select all
if(!function_exists('str_ireplace')) {
function str_ireplace($search, $replace, $subject, &$count = false) {
if(!is_array($search)) {
$search = array($search);
}
if(!is_array($replace)) {
$replace = array($replace);
}
$search = array_map(CreateFunction('$a','return \'#\'.preg_quote($a,\'#\').\'#i\';'),$search);
return preg_replace($search,$replace,$subject,-1,$count);
}
}of course, you could use the PHP Compatibility library from Pear: http://pear.php.net/package/PHP_Compat