批量去除PHP文件中bom的PHP代码

需要去除BOM,就把附件里的tool.PHP文件放到目标目录,然后在浏览器访问tool.PHP即可!
<div class="codetitle"><a style="CURSOR: pointer" data="87539" class="copybut" id="copybut87539" onclick="doCopy('code87539')"> 代码如下:

<div class="codebody" id="code87539">
<?PHP
//此文件用于快速测试UTF8编码的文件是不是加了BOM,并可自动移除
$basedir="."; //修改此行为需要检测的目录,点表示当前目录
$auto=1; //是否自动移除发现的BOM信息。1为是,0为否。
//以下不用改动
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {
if ($file!='.' && $file!='..' && !is_dir($basedir."/".$file))
echo "filename: $file ".checkBOM("$basedir/$file")."
";
}
closedir($dh);
}
function checkBOM ($filename) {
global $auto;
$contents=file_get_contents($filename);
$charset[1]=substr($contents,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.");
} 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);
}
?>

PHP批量去除PHP文件中bom的代码
<div class="codetitle"><a style="CURSOR: pointer" data="79253" class="copybut" id="copybut79253" onclick="doCopy('code79253')"> 代码如下:
<div class="codebody" id="code79253">
<?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")."
";
}else{
$dirname = $basedir."/".$file;
checkdir($dirname);
}
}
}
closedir($dh);
}
}
function checkBOM ($filename) {
global $auto;
$contents = file_getcontents($filename);
$charset[1] = substr($contents,1);
$charset[2] = substr($contents,1);
$charset[3] = substr($contents,1);
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
if ($auto == 1) {
$rest = substr($contents,automatically removed.
http://www.joyphper.net");
} else {
return ("BOM found.");
}
}
else return ("BOM Not Found.");
}
function rewrite ($filename,$data) {
$filenum = fopen($filename,$data);
fclose($filenum);
}
?>

bom

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...