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 $str1 = Str_replace ("Red", "Black", "Red green yellow Pink Purple"), echo $str 1. ""; /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);p rint _r ($str 1);? >
<?php//instance three: Array substitution array, map substitution $arr1 = 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);p Rint_r ($con _rep);? >
<?php//instance four: If the $search is an array, the $replace is a string $search = Array ("Banana", "grape"), $replace = "tomato"; $arr = Array ("Banana", " Apple "," orange "," Grape "), $new _arr = Str_replace ($search, $replace, $arr, $count);p Rint_r ($new _arr);? >
This article from the "Golden Three" blog, declined to reprint!
PHP string Substitution str_replace () function 4 usage explanations