引用文件指的是 includerequire_once 引用其它文件引起的空白行, 这其实是你用记事本编辑 UTF-8 文件以后, 虽然你还是保存为 UTF-8 格式, 但系统会自动给文件加两个 bom 标记, 但是 ie 只能忽略一个, 另一个就是空白行了
解决办法就是: 不要用记事本去编辑 UTF-8 文件, 要用其它工具, 比 DreamwEmEditor Visual Studio 2008 等编辑工具编辑 UTF-8 文件后保存
我的两个站用记事本编辑后顶部就有空白行, 起初以为是 CSS 设置问题, 结果是 bom 标记引起的
还有一种办法, 如果你是大量文件都这样我们可使用一个 php 函数来搞定, 把以下代码复制到一个 PHP 文件里面, 然后放在需要清除 BOM 头的目录一下运行, 就可以批量把 PHP 空白的首行清除掉, 太给力了, 代码如下:
- <?php
- if (isset($_GET['dir'])) { // 设置文件目录
- $basedir = $_GET['dir'];
- } else {
- $basedir = '.';
- }
- $auto = 1;
- checkdir($basedir);
- function checkdir($basedir) {
- if ($dh = opendir($basedir)) {
- while (($file = readdir($dh)) !== false) {
- if ($file != '.' && $file != '..') {
- if (!is_dir($basedir . "/" . $file)) {
- echo "filename: $basedir/$file" . checkBOM("$basedir/$file") . " ";
- } else {
- $dirname = $basedir . "/" . $file;
- checkdir($dirname);
- }
- }
- }
- closedir($dh);
- }
- }
- function checkBOM($filename) {
- global $auto;
- $contents = file_get_contents($filename);
- $charset[1] = substr($contents, 0, 1);
- $charset[2] = substr($contents, 1, 1);
- $charset[3] = substr($contents, 2, 1);
- if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
- if ($auto == 1) {
- $rest = substr($contents, 3);
- rewrite($filename, $rest);
- return ("BOM found, automatically removed.");
- } else {
- return ("BOM found.");
- }
- } else return ("BOM Not Found.");
- }
- function rewrite($filename, $data) {
- $filenum = fopen($filename, "w");
- flock($filenum, LOCK_EX);
- fwrite($filenum, $data);
- fclose($filenum);
- }
- ?>
来源: https://www.php1.cn/detail/php-5355315181.html