what is the syntax of the STR_IREPLACE() function in php?
str_ireplace(find,replace,string,count)
Parameter | Description |
---|---|
find | Required. Specifies the value to find |
replace | Required. Specifies the value to replace the value in find |
string | Required. Specifies the string to be searched |
count | Optional. A variable that counts the number of replacements |
examples of the STR_IREPLACE() function
Example 1. In this example, we replace the characters “WORLD” (case-insensitive) in the string “Hello world!” with “Peter”.
<?php
echo str_ireplace("WORLD","Peter","Hello world!");
?>
Example 2. In this example, we use str_ireplace() with an array and a count variable.
<?php
$arr = array("blue","red","green","yellow");
print_r(str_ireplace("RED","pink",$arr,$i)); // This function is case-insensitive
echo "Replacements: $i";
?>
Example 3. In this example, we use str_ireplace() with fewer elements in replace than find.
<?php
$find = array("HELLO","WORLD");
$replace = array("B");
$arr = array("Hello","world","!");
print_r(str_ireplace($find,$replace,$arr));
?>