Home > Article > Backend Development > PHP batch detection and removal of file BOM header code examples_PHP tutorial
The following code is PHP code to remove the BOM information of all files in the current directory and subdirectories, create a new file, place it in the root directory, and then access it with a browser.
$auto = 1;
checkdir($basedir);
function checkdir($basedir)
{
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {< | basedir/$file " . checkBOM("$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]) == " rest);
return ("BOM found, automatically removed."); "red">BOM found.
function rewrite($filename, $data)
{
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum , $data);
fclose($filenum);
}
?>
http://www.bkjia.com/PHPjc/767089.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/767089.html
TechArticle