PHP development, often part of the uft8 PHP file due to different BOM header causes a variety of errors and dislocation. Most of the so-called whereabouts of the online BOM tools are 2 goods, not available. The following section of code, please copy to a PHP file, and then upload to your site root directory, and then the front desk access, he will automatically the site under all the directories and subdirectories of the various documents of the BOM, will automatically judge Yo.
<?php
Set the root directory where you want to clear the BOM (all subdirectories and files will be scanned automatically)
$HOME = DirName (__file__);
If it is a Windows system, modify it to: $WIN = 1;
$WIN = 0;
?>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>utf8 BOM Cleaner </title>
<style>
body {font-size:10px; font-family:arial, Helvetica, Sans-serif; background: #FFF; color: #000;}
. FOUND {color: #F30; font-size:14px; font-weight:bold;}
</style>
<body>
<?php
$BOMBED = Array ();
Recursivefolder ($HOME);
Echo ' foreach ($BOMBED as $utf) {echo $utf. <br/>\n "; }
Echo ' </p> ';
Recursive scan
function Recursivefolder ($sHOME) {
Global $BOMBED, $WIN;
$win = ($WIN = = 1)? "\\" : "/";
$folder = Dir ($sHOME);
$foundfolders = Array ();
while ($file = $folder->read ()) {
if ($file! = "." and $file! = "...") {
if (filetype ($sHOME. $win. $file) = = "Dir") {
$foundfolders [Count ($foundfolders)] = $sHOME. $win 32. $file;
} else {
$content = file_get_contents ($sHOME. $win. $file);
$BOM = Searchbom ($content);
if ($BOM) {
$BOMBED [Count ($BOMBED)] = $sHOME. $win 32. $file;
Move out of BOM information
$content = substr ($content, 3);
Write back to the original file
File_put_contents ($sHOME. $win. $file, $content);
}
}
}
}
$folder->close ();
if (count ($foundfolders) > 0) {
foreach ($foundfolders as $folder) {
Recursivefolder ($folder, $win 32);
}
}
}
Search the current file for a BOM
function Searchbom ($string) {
if (substr ($string, 0,3) = = Pack ("CCC", 0XEF,0XBB,0XBF)) return true;
return false;
}
?>
</body>
The most awesome file in history. BOM Header cleanup code, universal detection clear PHP,JS, etc.