在我的論壇URL中,其中存在「index.php」。我想用「測試」來替換它。在我的PHP文件,我有這樣一行:使用preg_replace要更改index.php要測試
// Makes it easier to refer to things this way.
$scripturl = $boardurl . '/index.php';
我嘗試了將其更改爲:
// Makes it easier to refer to things this way.
$scripturl = $boardurl . '/test';
然而,返回404錯誤。我被告知我需要使用preg_replace來實現這一點。我看了一下PHP手冊,它說我需要一個模式,替換和一個主題。我對主題部分感到困惑。
我想這一點,但沒有得勝
// Makes it easier to refer to things this way.
$scripturl = $boardurl . preg_replace('/index.php','/test','?');
下面是一個例子URL: 「domain.com/index.php?node=forum」
我希望它看起來像「 domain.com/test?node=forum「
你試過用'/ test /'而不是'/ test'嗎?這可能是你的問題。 – Charles
是的,但仍然是同樣的問題。 – Xarcell
不會str_replace更容易爲您的目的? http://php.net/manual/en/function.str-replace.php另外,你有沒有嘗試迴應你創建的字符串,以確保他們看起來你期望他們? – lostphilosopher