PHP replace string by str_ireplace() for case-insensitive

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:

  1. Find (value to be replaced).
  2. Replace (value to be replaced by).
  3. 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


 

See another example with a variable:

Experience this example online


Output

Hello Peter!

 

Also see PHP strings

Was this article helpful?

Related Articles

Leave A Comment?