-1
str_replace($search, $replace, $subject);

我对 $search 字符串和 $replace 字符串没有任何问题。

但是如何使用str_replace()$search 字符串和 $replace 数组呢?

4

1 回答 1

1

str_replace()文档提供了一个清晰的示例,如何使用数组(大小相等):

// 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数组,而且“奇怪”:应该使用哪个数组值进行匹配?

于 2013-01-20T13:34:33.290 回答