在修改网站文件时,一不心就会产生bom头,导致验证码不显示等网站异常问题, 那我们就会批量操作删除bom头,将以下文件保存为bom.php,并上传到空间根目录下,用域名/bom.php执行,就可快速的解决问题,附代码:
04 |
* http://blog.kilvn.com/ |
07 |
if (isset($_GET[ 'dir' ])){ //设置文件目录 |
08 |
$basedir=$_GET[ 'dir' ]; |
17 |
function checkdir($basedir){ |
18 |
if ($dh = opendir($basedir)) { |
19 |
while (($ file = readdir($dh)) !== false ) { |
20 |
if ($ file != '.' && $ file != '..' ){ |
21 |
if (!is_dir($basedir. "/" .$ file )) { |
22 |
echo "filename: $basedir/$file " .checkBOM( "$basedir/$file" ). " <br>" ; |
24 |
$ dirname = $basedir. "/" .$ file ; |
33 |
function checkBOM($filename) { |
35 |
$contents = file_get_contents($filename); |
36 |
$charset[1] = substr($contents, 0, 1); |
37 |
$charset[2] = substr($contents, 1, 1); |
38 |
$charset[3] = substr($contents, 2, 1); |
39 |
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) { |
41 |
$rest = substr($contents, 3); |
42 |
rewrite ($filename, $rest); |
43 |
return ( "<font color=red>BOM found, automatically removed.</font>" ); |
45 |
return ( "<font color=red>BOM found.</font>" ); |
48 |
else return ( "BOM Not Found." ); |
51 |
function rewrite($filename, $data) { |
52 |
$filenum = fopen($filename, "w" ); |
53 |
flock($filenum, LOCK_EX); |
54 |
fwrite($filenum, $data); |
|
本文来源:一虎网络,转载请注明出处!如果需要石家庄
网站建设 石家庄小程序开发 石家庄微信开发 石家庄APP开发请联系谢经理,我们将提供最优质的服务!
联系方式:手机:15343118440 QQ:2488740351或扫一扫下面二维码加我微信: