how to use str_ireplace function in php

str_ireplace function is one of PHP String function .

with the help of this function we can replace the space or something from the string in php with case insensitive effect.

Syntax :-  str_ireplace(find,replace,string,count)

Case insensitive means here str_ireplace function ignore the case and the same for in all case like – WORD,Word,WOrD,WoRD

it will treat all the above word same .Let us take some examples

$our_string  =  ‘Hello SAM’;

And we want to replace the SAM with Ram than we can do this str_ireplace function

$str = str_ireplace(“SAM”,”Ram”,$our_string);

echo $str ; // output is Hello Ram

or

$str = str_ireplace(“SaM”,”Ram”,$our_string);

echo $str ; // output is Hello Ram

or

$str = str_ireplace(“SAm”,”Ram”,$our_string);

echo $str ; // output is Hello Ram

or

$str = str_ireplace(“sAM”,”Ram”,$our_string);

echo $str ; // output is Hello Ram

We can see that in all the case we get the same output .which is a quality of case insensitive of str_ireplace function in PHP.

Check it also

check documentation

Leave a Reply

Your email address will not be published. Required fields are marked *