Home >>PHP String Functions >PHP str_ireplace() Function
PHP str_ireplace() function is used to replace some characters with some other characters in a given input string. It is similar to the str_replace() function but it is case-insensitive.
Syntax:
str_ireplace($find, $replace, $string, $count );
Parameter | Description |
---|---|
find | This is a required parameter. This parameter defines the value to find. |
replace | This is a required parameter. This parameter defines the value to replace the value in find. |
string | This is a required parameter. This parameter contains the string to be searched. |
count | This is an optional parameter. This parameter contains a variable that counts the number of replacements. |
Here is an example of str_ireplace() function in PHP:
<html> <body> <?php echo str_ireplace("Abhi","Jerry","Hello everyone!! I am Abhi."); ?> </body> </html>
Here is an another example of str_ireplace() function in PHP:
<html> <body> <?php $str= "Red yelloe pink green red black red blue black white red black"; print_r(str_ireplace("Red","Black",$str,$i)); // Case-insensitive echo "<br>" . "Replacements: $i"; ?> </body> </html>