我目前有一個header.php頁面,它存儲我的頁眉和佈局的所有樣式和位置。然後我有一個contactus.php頁面,其中包含header.php頁面。在PHP中,在計算值之前修改包含文件中變量的值
-----CONTACTUS.PHP:
<?php
include 'header.php'
$classnamehere='"linkStyleTwo"' //Here is where I want to update the value
?>
在我的網頁頂部的主要環節是使用某種方式稱呼:
------HEADER.PHP:
<?php
$classnamehere= '"linkStyleOne"' ?>
<a href="http://www.google.com" class= <?php echo $classnamehere ; ?>......
我想改變鏈接的風格,該人已點擊,使其彈出向用戶表明他們在哪個頁面上。目前,當我嘗試更改contactus.php中的$ classnamehere的值(通過簡單地分配一個新值)來更改在<a href>
標籤內打印的類時,什麼都不會發生。它執行include命令,並輸出header.php中聲明的值,而忽略我嘗試更改新頁面上的值。
是否有任何方法只改變contactus.php內的值,同時仍然保持header.php內的初始值,以便所有其他頁面仍然可以使用'默認'風格?
編輯:內contactus.php,我可以更改從header.php獲得(包括)變量的值,而不實際「改變」全局變量?
哪裏abouts你重寫' $ classnamehere'變量? – billyonecan 2013-05-01 07:20:53
我想從contactus.php中覆蓋。 – 2013-05-01 07:24:08
我只是使用file_get_contents()加載header.php,做一個搜索並替換「linkStyleOne」,然後eval()字符串。 – cleong 2013-05-01 08:27:39