我試圖讓我的生活變得更容易,並使所有頁面從一個文件具有相同的頁腳和頭部內容,這是我迄今爲止:添加大量的html和php內容作爲PHP變量
頁的內容
<?php
include ("content.php");
echo $page_header;
?>
<div id="content">
</div>
<?php
echo $page_footer;
?>
content.php
<?php
// This is the header which we want to have on all pages
$page_header = include ("resources/content/header.php");
// This is the footer which we want on all pages
$page_footer = include ("resources/content/footer.php");
?>
的header.php例
<html>
<head>
<title>This is my title</title>
</head>
<body>
<div id="logo">
</div>
Footer.php例
<div id="footer">Copyright to me!</div>
</body>
</html>
的我有問題是我的header.php內容是不是所有與頁面格式顯示,並導致問題。 header.php確實包含了一些php if
聲明和一些內嵌的javascript ...應該這樣嗎?
有沒有更好的方法呢?
請注意:我使用本地PHP 5,我的服務器是PHP 4所以答案需要兩個
'include(「resources/content/footer.php」);'而不是將它分配給一個變量 –
真的沒有什麼真正的錯誤,你有沒有嘗試驗證你的HTML?有沒有任何理由一些有條件的PHP或內聯JS應該有所作爲,你可以發佈header.php內容 – dougajmcdonald
我寫了類似的問題[這裏](http://stackoverflow.com/questions/18937026/insert -page功能於HTML設計/ 18937678#18937678)。 – mdesdev