本文介紹下php替換字符串的方法,除了基本的一個(gè)字符串替換外,本文示例的兩個(gè)不同的替換應(yīng)用,有需要的朋友參考下。
示例:
str_replace(array("a","e"),"c","my name is jim!") 把字符串中a和e替換成c。
結(jié)果為:"my ncmc is jim!".
示例2:
str_replace(array("m","i"),array("n","z"),"my name is jim!") 把字符串m替換成n,把字符串中i替換成z。
結(jié)果為:"ny name zs jzm!".
完整示例:
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$onlyconsonants = str_replace($vowels, "","Hello World of PHP");
echo $onlyconsonants;