Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Does anyone know of a function that works like str_ireplace in PHP < 5?

str_ireplace(a,b,c) replaces a with b in c, just like str_replace, but case  


- Nicolaas  

Re: str_ireplace


Quoted text here. Click to load it

mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [,  
int limit [, int &count]] )

then just run it with a flag of  i.  so take your example:

preg_replace('/b/i', 'a', 'c')

a better example of this would be:
$subject = 'this is my MOM';
$pattern = '/mom/i';
$replace = 'DAD';
echo preg_replace($pattern, $replace, $subject);

Quoted text here. Click to load it

Mike Willbanks
Zend Certified Engineer

Re: str_ireplace

Hi why don't you just do the following to get the same result?

$var = strtolower$var); //convert string to lower case
str_ireplace(..., $var);

if you don't want to convert the original string just do

$var = 'SomE STrinG';

$testvar = strtolower($var);
$str_ireplace(..., $testvar);


Quoted text here. Click to load it

Site Timeline