例如,我已經叫'include.php'
或'include.html'
一個頁面,其中包含下面的代碼行:如何在PHP中包含頁面並替換其中的所有變量?
<h1>Hi {$yourname}, this is a header.</h1>
現在,我想包括使用另一頁上PHP這個頁面,讓我們'index.php'
說使用:
<?
$yourname = 'Bir';
include 'include.php';
?>
當我包括它,頁面顯示:
<h1>Hi {$yourname}, this is a header.</h1>
變量$ yourname不會被替換爲它的值"Bir"
。
我該如何解決這個問題?
你總是可以只使用'<?= $提供yourname?>'而不是'<?PHP的echo $提供yourname?>' –
有一些模板引擎可能適合你的語法。 –
如果可能,你能提供一些鏈接嗎? @MarkusMalkusch – user3382146