要移除BOM,就把附件裡的tool.php檔案放到目標目錄,然後在瀏覽器存取tool.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;
$c
$charset[1]=substr($contents, 0, 1);
$charset[1]=substr($contents, 0, 1); id ($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); rite rite $filenum,$data);
fclose($filenum);
}
?>
? (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);
}
}
}
closed dh);
}
}
function checkBOM ($filename) {
global $auto;
$contents = file_get_contents($filename);
$charset[1] = substr($contents, 0,$1); [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._http://www.joyphper.net");
} else {
return ("BOM found.");
}
}
else return ("BOM Not Found.");
}
else return ("BOM Not Found.");
}
else return ("BOM Not Found.");
}
else return ("BOM Not Found.");
}
else return ("BOM Not Found.");
}
eltion rewrite (rite $filename, $data) {
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}
}
?>
以上就介紹了Delphi單元檔案 批次移除PHP檔案中bom的PHP程式碼,包含了Delphi單元檔案方面的內容,希望對PHP教學有興趣的朋友有所幫助。
🎜