需要去除BOM,就把附件里的tool.php文件放到目标目录,然后在浏览器访问tool.php即可!
<BR><?php <BR>//此文件用于快速测试UTF8编码的文件是不是加了BOM,并可自动移除 <BR>$basedir="."; //修改此行为需要检测的目录,点表示当前目录 <BR>$auto=1; //是否自动移除发现的BOM信息。1为是,0为否。 <BR>//以下不用改动 <BR>if ($dh = opendir($basedir)) { <BR>while (($file = readdir($dh)) !== false) { <BR>if ($file!='.' && $file!='..' && !is_dir($basedir."/".$file)) <BR>echo "filename: $file ".checkBOM("$basedir/$file")." <br>"; <BR>} <BR>closedir($dh); <BR>} <BR>function checkBOM ($filename) { <BR>global $auto; <BR>$contents=file_get_contents($filename); <BR>$charset[1]=substr($contents, 0, 1); <BR>$charset[2]=substr($contents, 1, 1); <BR>$charset[3]=substr($contents, 2, 1); <BR>if (ord($charset[1])==239 && ord($charset[2])==187 && ord($charset[3])==191) { <BR>if ($auto==1) { <BR>$rest=substr($contents, 3); <BR>rewrite ($filename, $rest); <BR>return ("<font color="red">BOM found, automatically removed.</font>"); <BR>} else { <BR>return ("<font color="red">BOM found.</font>"); <BR>} <BR>}else <BR>return ("BOM Not Found."); <BR>} <BR>function rewrite ($filename, $data) { <BR>$filenum=fopen($filename,"w"); <BR>flock($filenum,LOCK_EX); <BR>fwrite($filenum,$data); <BR>fclose($filenum); <BR>} <BR>?> <BR>
PHP批量去除PHP文件中bom的代码
<BR><?php <BR>if (isset($_GET['dir'])){ //设置文件目录 <BR>$basedir=$_GET['dir']; <BR>}else{ <BR>$basedir = '.'; <BR>} <BR>$auto = 1; <BR>checkdir($basedir); <BR>function checkdir($basedir){ <BR>if ($dh = opendir($basedir)) { <BR>while (($file = readdir($dh)) !== false) { <BR>if ($file != '.' && $file != '..'){ <BR>if (!is_dir($basedir."/".$file)) { <BR>echo "filename: $basedir/$file ".checkBOM("$basedir/$file")." <br>"; <BR>}else{ <BR>$dirname = $basedir."/".$file; <BR>checkdir($dirname); <BR>} <BR>} <BR>} <BR>closedir($dh); <BR>} <BR>} <BR>function checkBOM ($filename) { <BR>global $auto; <BR>$contents = file_get_contents($filename); <BR>$charset[1] = substr($contents, 0, 1); <BR>$charset[2] = substr($contents, 1, 1); <BR>$charset[3] = substr($contents, 2, 1); <BR>if (ord($cha<mark>(本文来)源gaodaimacom搞#^代%!码&网(</mark><pre>搞gaodaima代码
rset[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._http://www.joyphper.net“);
} else {
return (“BOM found.“);
}
}
else return (“BOM Not Found.”);
}
function rewrite ($filename, $data) {
$filenum = fopen($filename, “w”);
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}
?>