Php 页眉、页脚div在单独文件中的位置
给定基本html结构: divs:wrapper、header、content、footer-我可以通过以下文件分隔div吗: header.phpPhp 页眉、页脚div在单独文件中的位置,php,html,Php,Html,给定基本html结构: divs:wrapper、header、content、footer-我可以通过以下文件分隔div吗: header.php <body> <div id=wrapper> <div id=header></div> <div id=content> index.php footer.php </div><!-- End of content --> <div id=foote
<body>
<div id=wrapper>
<div id=header></div>
<div id=content>
index.php
footer.php
</div><!-- End of content -->
<div id=footer></div>
</div><!-- End of wrapper -->
这样看来,我可以把大部分不必要的html推到一边,专注于编码内容
includes的问题是,我的包装器和内容div从一个文件开始,到另一个文件结束,这会生成eclipse编辑器视觉警告,让我很恼火(嘿,伙计,出了点问题,你需要修复这个…“黄色三角形!”符号在所有文件夹结构上)从下面示例中显示的脚本加载页眉和页脚的html文件
$(“文档”).ready(函数(){
$(“#header”).load(“header.html”);
$(“#footer”).load(“footer.html”);
}); 代码>
PHP允许您在当前运行的文件中包含其他文件,并带有语句
这将允许您在服务器上包含一个公共页眉和页脚,这样您就可以只将一个页面返回到浏览器,而无需请求其他HTML页面
header.php
<header>Place your header content here</header>
<footer>Place your footer content here</footer>
将标题内容放在此处
footer.php
<header>Place your header content here</header>
<footer>Place your footer content here</footer>
将页脚内容放在此处
index.html
<html>
<body>
<?php include 'header.php';?>
<p>Some text.</p>
<p>Some more text.</p>
<?php include 'footer.php';?>
</body>
</html>
一些文本
还有一些文字
忽略它如果您使用的是include,您的IDE无法看到合并的php文件的结果。这不适用于您的html结构。您尝试将html文件加载到具有您从未使用过的ID的div。