发布时间:2022-11-13 10:46:05
一键去除网页BOM属性【解决乱码,头部空白,验证码不显示问题】
几个常出现的问题:
1.网站打开空白
2.页面头部出现多余的空白
3.网站出现乱码,如“锘�”
4.后台登录验证码不显示
解决方案:
1.选用专业的编辑器,例如notepad++,sublime,editplus这样不会自动签名。
2.sublime通过如下操作File -> Save with Encoding -> UTF-8保存后即可去除bom
3.notepad++选中格式 -> 以UTF-8格式编码 选项即可去除
4.用如下方法可一次性清理网页所有文本文件的bom
复制下面代码
[Del the delbom.php file]复制上面的代码
";if (!is_dir($dir))die("$dir not exists");$auto = 1; checkdir($dir); 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")."
\n"; }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.\n"); } else { return ("BOM found.\n"); } } else return ("BOM Not Found.\n"); } function rewrite ($filename, $data) { $filenum = fopen($filename, "w"); flock($filenum, LOCK_EX); fwrite($filenum, $data); fclose($filenum); } ?>
使用方法:复制上面代码到一个新建的delbom.php(用记事本或者是文本编辑器打开此文件)的文件中,上传到网站根目录,然后访问您的站点,比如http://www.**.com/delbom.php 即可清理所有网页中存在的bom便签。