替换某个字符串中的一个或若干个字串为数组中某些值
php本身有自带的函数,可以不用循环非常高效的实现其效果:
实例代码:
$phrase = "You should eat fruits , vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy = array("pizza", "beer","banana" ); $newphrase = str_replace($healthy, $yummy, $phrase);
print_r($newphrase);结果显示为:
You should eat pizza , beer, and banana every day.