我有模板DB例如客戶選擇此模板PHP str_replace函數在文本
$var = "It is a long established fact that a reader will be distracted by the
this is [Dateiname]
its your [Format]
your alang [Ausgangssprache]
your zlang [Zielsprache]
readable content of a page when looking at its layout. The point of using Lorem Ipsum is";
需要更換[Dateiname] [Format] [Ausgangssprache] [Zielsprache]
我有3個職位,並在我的職位DB I有Dateiname,Format,Ausgangssprache,Zielsprache
filds
當我選擇那個filds例如
$result="";
for($i = 0; i<count($posts); $i++)
{
$replaceText = array(
'[Dateiname]',
'[Format]',
'[Ausgangssprache]',
'[Zielsprache]',
);
$replacePost = array(
$filename[$i],
$filetype[$i],
$ausgangsspracheOne['de'],
$zeilspracheOne['de'],
);
$result.= str_replace($needReplace, $replacePost, $var);
}
我的結果顯示我的這段文字,例如3次:
這是一個歷史悠久的事實,讀者將通過 [POST1] [titel1] [DESC1] [YEAR1]分心
這是一個長期建立的事實,讀者將通過 [POST2] [titel2] [DESC2] [YEAR2]
分心這是一個歷史悠久的事實,讀者將被分心的 [post3] [titel3] [desc3] [year3]
我需要像這樣,有沒有可能?
這是一個歷史悠久的事實,讀者將通過
[post1] [titel1] [desc1] [year1] [post2] [titel2] [desc2] [year2] [post3] [titel3] [desc3] [year3]
你爲什麼要用str_replace?需要嗎? – davejal
沒有不需要 –