2013-01-20 63 views
-1
str_replace($search, $replace, $subject); 

我沒有問題,$搜索字符串和$替換字符串。php str_replace()字符串到數組錯誤

但是,我怎樣才能使用str_replace()與$搜索字符串和$替換數組?

+0

你是什麼意思'$ search string和$ replace array?'? –

回答

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作爲數組是不可能的,「怪異」:哪個數組值應該是用於比賽?

+0

謝謝,我明白你的意思 – vzhen