str ireplace in PHP

In this article I will explain how the str_ireplace() function can be used in PHP.
  • 1547

str_ireplace() function in PHP

  • The str_ireplace() function is used to replace some characters with some other characters in a string.
  • The str_ireplace() function is case-insensitive.
  • The str_ireplace() function is used to to perform a case-sensitive search.
  • The str_replace() function is binary-safe.

This function works by the following rules:

  • It returns an array, If the string to be searched is an array.
  • Find and replace is performed with every array element, If the string to be searched is an array.
  • If both find and replace are arrays, and replace has fewer elements than find, an empty string will be used as replace
  • The replace string will be used for every find value, If find is an array and replace is a string.

Syntax

str_ireplace(find,replace,string,count)

Parameter

  • find find is required parameter. it is specify for find the value.
  • replace replace is required parameter. it is specify for value to replace.
  • string string is required parameter. it is specify for search the string.
  • count count is optional parameter. it is variable that counts the number of replacements .
Example

The following example show to how the str_ireplace() function can be used in PHP.

<html>

<body>

<h3 style="color: red;">str_ireplace() function example in PHP</h3>

    <?php

    $arr = array("English".'<br/>',"Hindi".'<br/>',"Math".'<br/>',"Computer".'<br/>');

    print_r(str_ireplace("hindi","Science",$arr,$i));

    echo "<br/>Replacements: $i";

    ?>                

</body>

</html>

 

Output

str-ireplace-php.gif
You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.