Quick Reach
The str_ireplace function
In order to replace words in your strings with other words, you can use replace string function str_ireplace() in PHP. You can use str_replace() as well, however, this is case sensitive while str_ireplace() is not.
See an example of str_ireplace
PHP str_ireplace Syntax
Following is the syntax for PHP string replacement for case insensitive words:
str_ireplace(find,replace,string,count)
Where:
- Find (value to be replaced).
- Replace (value to be replaced by).
- String – that can be a string variable, static or an array.
Example of str_ireplace PHP function
The following example uses str_ireplace function to replace one word with another – both words use different cases for the demo.
Experience this example online
1
2
3
4
5
6
7
|
<h3>Example of str_ireplace()
<?php
echo str_ireplace(“mike”,“Peter”,“Hello Mike!”);
?>
|
See another example with a variable:
Experience this example online
1
2
3
4
5
6
7
|
<?php
$strReplaceExample = “Hello mike”;
echo str_ireplace(“Mike”,“Peter”,$strReplaceExample);
?>
|
Output
Hello Peter!
Also see PHP strings
Leave A Comment?