Computer >> Computer tutorials >  >> Programming >> PHP

str_ireplace() function in PHP


The str_ireplace() function is used to replace the characters with some other characters.

Note − The function is case-insensitive

Syntax

str_ireplace(find,replace,str,count)

Parameters

  • find − The value to be searched

  • replace − The value to replace the value in find

  • str − The string to be searched

  • count − The number of replacements

Return

The str_ireplace() function returns a string or array with the replaced values.

The following is an example −

Example

<?php
$str = "I am Amit";
$res = str_ireplace("Amit", "David", $str);
echo $res;
?>

The following is the output −

Output

I am David

Let us see another example −

Example

<?php
$myArr = array("one","two","three");
print_r(str_ireplace("three","four",$myArr,$c));
echo "<br>" . "Number of Replacements = $c";
?>

The following is the output −

Output

Array
(
   [0] => one
   [1] => two
   [2] => four
)
Number of Replacements = 1