<?php
This file is used to quickly test whether UTF8 encoded files are added to the BOM and can be automatically removed
by Bob Shen
$basedir = "."; Modify this behavior to detect the directory where the point represents the current directory
$auto = 1; Whether the discovered BOM information is automatically removed. 1 for Yes, 0 for No.
Do not change the following
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) {
$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) {
$rest =substr ($contents, 3);
Rewrite ($filename, $rest);
return true;
}
else return ("BOM not Found.");
}
function rewrite ($filename, $data) {
$filenum =fopen ($filename, "w");
Flock ($filenum, LOCK_EX);
Fwrite ($filenum, $data);
Fclose ($filenum);
}
?>