欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2012年03月13日 23:41:01   作者:  
今天搜索查看網(wǎng)頁源碼時(shí)為什么開頭會(huì)有空行這個(gè)問題時(shí)找到的,批量去除PHP文件中bom的PHP代碼
需要去除BOM,就把附件里的tool.php文件放到目標(biāo)目錄,然后在瀏覽器訪問tool.php即可!
復(fù)制代碼 代碼如下:

<?php
//此文件用于快速測(cè)試UTF8編碼的文件是不是加了BOM,并可自動(dòng)移除
$basedir="."; //修改此行為需要檢測(cè)的目錄,點(diǎn)表示當(dāng)前目錄
$auto=1; //是否自動(dòng)移除發(fā)現(xiàn)的BOM信息。1為是,0為否。
//以下不用改動(dòng)
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {
if ($file!='.' && $file!='..' && !is_dir($basedir."/".$file))
echo "filename: $file ".checkBOM("$basedir/$file")." <br>";
}
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.</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);
}
?>

PHP批量去除PHP文件中bom的代碼
復(fù)制代碼 代碼如下:

<?php
if (isset($_GET['dir'])){ //設(shè)置文件目錄
$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://www.joyphper.net>http://www.joyphper.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);
}
?>

相關(guān)文章

最新評(píng)論