替换某个字符串中的一个或若干个字串为数组中某些值
php本身有自带的函数,可以不用循环非常高效的实现其效果:
实例代码:
1 |
$phrase
= "You should eat fruits , vegetables, and fiber every day." ;<br> $healthy
= array ( "fruits" , "vegetables" , "fiber" );<br> $yummy
= array ( "pizza" , "beer" , "banana"
);<br><br> $newphrase
= str_replace ( $healthy , $yummy , $phrase );<br> |
print_r($newphrase);结果显示为:
You should eat pizza , beer, and banana every day.
PHP 中替换若干字符串字串为数组中的值,不用循环,非常高效,布布扣,bubuko.com
PHP 中替换若干字符串字串为数组中的值,不用循环,非常高效
原文:http://www.cnblogs.com/share123/p/3658693.html