What this article brings to you is about the method of replacing the Str_replace () function with the PHP string. (four kinds), there is a certain reference value, the need for friends can refer to, I hope to help you.
The following article to share the PHP string replacement str_replace () function 4 uses, the specific content is as follows:
Mixed Str_replace (mixed $search, mixed $replace, mixed $subject [, int & $count])
The function returns a string or an array. The string or array is the result of replacing all search in subject with replace.
1, $search, the string to replace, or the array
2. $replace, the string or array to replace
3. $subject, the string or array being queried
4, $count, optional, if specified, will be set to replace the number of times
5. Return value: The function returns the replaced array or string (reborn)
<?php//instance One: String substitution string $str 1 = str_replace ("Red", "Black", "Red green Yellow Pink Purple "); echo $str 1. ""; The output is black green yellow pink purple?><?php//instance two: String substitution array key value $arr = Array ("Blue", "Red", "green", "yellow"); $str 1 = str_replace ("Red", "pink", $arr, $i); Print_r ($str 1);? ><?php//Instance three: Array substitution array, map substitution $arr 1 = array ("Banana", "orange"); $arr 2 = Array ("Pitaya", "tomato"); $con _arr = Array ("Apple", "orange", "banana", "grape"); $con _rep = Str_replace ($arr 1, $arr 2, $con _arr, $count); Print_r ($con _rep);? ><?php//Instance four: $search = Array ("Banana", "grape") if the array is $replace as a string $search; $replace = "tomato"; $arr = Array ("Banana", "apple", "orange", "Grape"); $new _arr = Str_replace ($search, $replace, $arr, $count); Print_r ($new _arr);?