数据什么的都么有问题,配置好rewrite以后,访问网站,发现样式变动了,网站上方空出了一块
我用chrome浏览器的审查元素一看,发现head里的内容全到Body里了,而且body的最开始出多出了一块带引号的空白!
 
但是如果右键查看源代码的话,代码是正确的,没有问题!
 
 
正常状态
 

 
 
错误状态
 
 
求大牛解救
问题原因:
网站采用了UTF-8无BOM编码,但是在使用include或者require包含文件的时候,包含了一个UTF-8有BOM的文件,就产生上述现象。
解决方法:
对网站所有文件进行去BOM操作
 
 
clearBOM.php(放到根目录下执行,执行前先备份网站,以备不测)
 
02 | 
$basedir = str_replace(‘/clearBOM.php‘,‘‘,str_replace(‘\\‘,‘/‘,dirname(__FILE__))); | 
 
05 | 
function checkdir($basedir){ | 
 
06 | 
    if ($dh = opendir($basedir)) { | 
 
07 | 
        while (($file = readdir($dh)) !== false) { | 
 
08 | 
            if ($file != ‘.‘ && $file != ‘..‘){ | 
 
09 | 
                if (!is_dir($basedir.‘/‘.$file)) { | 
 
10 | 
                    $filename = $basedir.‘/‘.$file; | 
 
11 | 
                    echo ‘filename:‘.$basedir.‘/‘.$file.checkBOM($filename).‘<br>‘; | 
 
13 | 
                    $dirname = $basedir.‘/‘.$file; | 
 
22 | 
function checkBOM ($filename) { | 
 
24 | 
    $contents = file_get_contents($filename); | 
 
25 | 
    $charset[1] = substr($contents, 0, 1); | 
 
26 | 
    $charset[2] = substr($contents, 1, 1); | 
 
27 | 
    $charset[3] = substr($contents, 2, 1); | 
 
28 | 
    if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) { | 
 
30 | 
            $rest = substr($contents, 3); | 
 
31 | 
            rewrite ($filename, $rest); | 
 
32 | 
            return ‘<font color=red>BOM found,automatically removed.</font>‘; | 
 
34 | 
            return ‘<font color=red>BOM found.</font>‘; | 
 
37 | 
        return ‘BOM Not Found.‘; | 
 
41 | 
function rewrite ($filename, $data) { | 
 
42 | 
    $filenum = fopen($filename, ‘w‘); | 
 
43 | 
    flock($filenum, LOCK_EX); | 
 
44 | 
    fwrite($filenum, $data); |