The difference between PHPstr_replace () and str_ireplace () is that the str_replace () function and str_ireplace () function in PHP are many functions in the program, its main function is to use a string to replace other characters in the string. The following describes the differences and explanations between Str_replace PHP str_replace () and str_ireplace ().
The str_replace () function and str_ireplace function of PHP are many functions in the program. Their main function is to use one string to replace other characters in the string. The following describes how to use it.
The Str_replace function is case sensitive. Use str_ireplace () to perform a case-insensitive search, and the rest should be no different.
Syntax
str_replace(find,replace,string,count)
Parameter description
| Find |
Required. Specifies the value to be searched. |
| Replace |
Required. Required replacementFindValue. |
| String |
Required. Specifies the string to be searched. |
| Count |
Optional. A variable that counts the number of replicas. |
Example 1
str_replace("world","John","Hello world!")DE>;?>
Output:
Hello John!
Example 2
In this example, we will demonstrate the str_replace () function with array and count variables:
str_replace("red","pink",$arr,$i)DE>);echo "Replacements: $i";?>
Output:
Array([0] => blue[1] => pink[2] => green[3] => yellow)Replacements: 1
Example 3
str_replace($find,$replace,$arr)DE>);?>
Output:
Array([0] => B[1] =>[2] => !)