The substr_replace () function is used to replace part of a string with another string, and returns a mixed type.
echo substr_replace ('abcdef', '###', 1 ); // output a ### echo substr_replace ('abcdef', '###', 1, 2 ); // output a ### def echo substr_replace ('abcdef', '###', -3, 2 ); // output abc ### f echo substr_replace ('abcdef', '###', 1, -2 ); // output a ### ef
The str_replace () function replaces some characters in a string with a string and returns a mixed type.
echo str_replace("world","earth","Hello world!"); //输出 Hello earth! // Replace multiple, and the second parameter is null character echo str_replace ("o", "", "Hello world!" ); // Output Hell wrld! //使用数组 $arr = array("e", "o"); $arr2 = array("x", "y"); echo str_replace($arr, $arr2, "Hello World of PHP", $i); //输出 Hxlly Wyrld yf PHP echo $i; //输出4