What is a BOM header?
In the Utf-8 encoded file BOM in the file head, occupies three bytes, used to indicate that the file belongs to the Utf-8 code, now has a lot of software to identify the BOM header, but some do not recognize the BOM header, such as PHP can not identify the BOM header, This is also the reason why you can make mistakes when you edit the Utf-8 encoding with Notepad.
The bulk removal of the BOM header code looks like this:
<?php if (isset ($_get[' dir ')) {//Set file directory $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); }?>
PS: Remove the method of BOM head, simple is the following two kinds:
1, EditPlus to the method of BOM head
After the editor adjusts to the UTF8 encoding format, the saved file is preceded by a string of hidden characters (also the BOM), which is used by the editor to identify whether the file is encoded in UTF8.
Run EditPlus, click Tools, select Preferences, select files, UTF-8 identity option always delete signature,
Then the php file edited and saved after the PHP file is not with the BOM.
2, UltraEdit remove the BOM head method
After opening the file, save as an option in the encoding format selected (Utf-8 no BOM header), ok OK
It's easy to get rid of the BOM header.
Another piece of discussion utf8 BOM information
BOM refers to the storage of the PHP file itself as a UTF-8 with the BOM, ordinary pages of Chinese garbled method is generally not caused by this reason.
Header ("content-type:text/html; Charset=utf-8 ");
This sentence controls how the HTML output page is encoded,
The BOM is only available when the "notepad" is stored as UTF-8 under Windows, which can be deleted by Winhex the 2 bytes that begin with.
Within the Dreamweaver coding settings can be set up with a BOM, generally as long as the output of PHP is not a picture (GDI Stream), the BOM will not cause problems.
GDI Stream appears as a red fork if it has an extra character at the beginning.