【发布时间】:2013-09-12 20:38:32
【问题描述】:
我在包含多个 html 页面时遇到问题。 我有主 index.html,但它开始有点过于复杂,所以我决定将它拆分为多个 html 文件,并使用 php 将每个文件导入单个 index.php。
index.php 文件
<?php
include('head.html');
include('header.html');
include('slideshow.html');
include('pictureGalery.html');
include('footer.html');
include('closer.html');
?>
使用我发现的 Google Chrome 开发者工具,该 php 还包括一些空格(您可以在 div 标题、内容、容器等之间的图片中看到它们... 通过一些谷歌搜索,我发现了一些关于这个问题的弧线,比如:
- PHP include causes white space at the top of the page(我无法使用edit cmd命令,因为我有win7 64位,并且没有在那里实现。您只能使用“打开记事本”命令,但这些空格在记事本中不可见。
- UTF-8 Without BOM?
- PHP include() before doctype, causing a white space
我也尝试过导入 reset.css 文件 (http://meyerweb.com/eric/tools/css/reset/),但也没有用。对我来说似乎工作的唯一方式是发布 cebasso (https://stackoverflow.com/a/14362246/1784053) 的方式。但我觉得这种方式有点过于激进和缺乏效果。
任何其他想法如何解决这个问题?
【问题讨论】:
-
but these whitespaces are not visible in notepad.-- 记事本不是唯一的文本编辑器。试试不同的,也许?试试记事本++。 -
还要确保您包含的文件没有尾随空行,php include 会将它们添加到原始文档中
-
+1 for Notepad++ 我最喜欢的文本编辑器。
-
@AmalMurali Notepad++、VisualStudio 2010、Dreamweaver、Eclipse.. 都一样。我没有看到这 3 个 BOM 字符
-
@jayadev 代码前后没有空行
标签: php html whitespace