我有一個輸出php啓用的模板。但是我無法讓str_replace工作。見下面的代碼。如果我只是把{title}沒有任何PHP然後它的作品。但是,當我包含php並將{title}放入str_replace函數中時,我什麼也沒有顯示。我試圖用簡單的回聲「測試」PHP;它的工作。它只是不分析{title}或其他字段標籤。expressionEngine php解析str_replace不起作用
{exp:channel:entries channel="one" url_title="{segment_2}"}
<?php
echo str_replace('old', 'new', '{title}');
?>
{/exp:channel:entries}
@thanks @rjb,我應該使用'segment_3'而不是'segment_2'。它現在工作,但是,如果我有以下str_replace數組的話,它不起作用。 PHP似乎不認可標題。 '$ searchArray = array(「on」,「two」,「thre」,「fou」); $ replaceArray = array(「one」,「two」,「three」,「four」); $ intoString =「{title}」; echo str_replace($ searchArray,$ replaceArray,$ intoString);'爲什麼'{title}'在這裏不被識別。 – Pinkie
以下代碼適用於我:[Screenshot](http://i.stack.imgur.com/9odhR.png)或[Pastie](http://pastie.org/pastes/2175892/text) – rjb