我试图让我的生活变得更容易,并使所有页面从一个文件具有相同的页脚和头部内容,这是我迄今为止:添加大量的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