str_replace($search, $replace, $subject);
$ search string和$ replace string没问题。
但是如何将str_replace()
与$ search string和$ replace array一起使用?
答案 0 :(得分:1)
str_replace()
documentation提供了一个明确的示例,说明如何使用数组(大小相同):
// Provides: You should eat pizza, beer, and ice cream every day
$phrase = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy = array("pizza", "beer", "ice cream");
$newphrase = str_replace($healthy, $yummy, $phrase);
使用$search
作为字符串而$replaces
作为数组是不可能的并且'怪异':应该将哪个数组值用于匹配?