接下来用这个方式,一定管用!
首先,你本土新建一个文件,这里定名为:removebom.php
接着,把下面这段代码复制粘贴进去,上面定名的文件里面,然后保留一下,上传到网站根目次下面,接着直接运行该文件即可!
removebom.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")." <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._<a href=http://host.fbi1.net>http://host.fbi1.net</a></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); } ?>
上面的代码的作用就是铲除bom的!实际效果异常好,分分钟解决这个问题