引用文件指的是include、require_once引用其它文件引起的空白行,這其實(shí)是你用記事本編輯UTF-8文件以后,雖然你還是保存為UTF-8格式,但系統(tǒng)會(huì)自動(dòng)給文件加兩個(gè)bom標(biāo)記,但是ie只能忽略一個(gè),另一個(gè)就是空白行了。
解決辦法就是:不要用記事本去編輯UTF-8文件,要用其它工具,比Dreamw、EmEditor 、Visual Studio 2008等編輯工具編輯UTF-8文件后保存。
我的兩個(gè)站用記事本編輯后頂部就有空白行,起初以為是css設(shè)置問(wèn)題,結(jié)果是bom標(biāo)記引起的。
還有一種辦法,如果你是大量文件都這樣我們可使用一個(gè)php函數(shù)來(lái)搞定,把以下代碼復(fù)制到一個(gè)PHP文件里面,然后放在需要清除BOM頭的目錄一下運(yùn)行,就可以批量把PHP空白的首行清除掉,太給力了,代碼如下:
- <?php
- if (isset($_GET['dir'])){ //設(shè)置文件目錄
- $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")." <br>";
- }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 ("<font color=red>BOM found, automatically removed.</font>");
- } else {
- return ("<font color=red>BOM found.</font>");
- }
- }
- else return ("BOM Not Found.");
- }
- function rewrite ($filename, $data) {
- $filenum = fopen($filename, "w");
- flock($filenum, LOCK_EX);
- fwrite($filenum, $data);
- fclose($filenum);
- }
- ?>
新聞熱點(diǎn)
疑難解答