Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn that the BOM in the UTF-8 encoding file is in the file header and occupies three bytes to indicate that the file belongs to the UTF-8 encoding, currently, many software programs recognize bom headers, but some cannot recognize bom headers. For example, PHP cannot recognize bom headers, this is also the cause of an error when editing UTF-8 encoding in notepad. BOM is only available in WINDOWS when the "Notepad" storage for the UTF-8, this can be used to remove the first two bytes with WINHEX. You can set whether to include BOM in the Code settings in dreamweaver. Generally, BOM will not cause problems as long as the output of php is not an image (GDI Stream. If the GDI Stream is enabled
To remove the bom header, there are two simple methods:
1. How to remove the BOM header from editplus
After the editor is adjusted to the UTF8 encoding format, a hidden character (BOM) is added before the saved file, which is used by the editor to identify whether the file is UTF-8 encoded. Run Editplus, click the tool, select preference, select the file, select the UTF-8 ID alWays Delete the signature, and then the PHP file after editing and saving the PHP file is without BOM.
2. How to remove the bom header from ultraedit
After opening the file, select the encoding format of the Save As option (UTF-8 without bom header) and click OK.
If the PHP program needs to remove the Bom header, you can also use the 92wcms. php program in the directory to remove it.
Run the code once.
If (isset ($ _ GET ['dir']) {// config the basedir
$ 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 );
}
}
}
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 ("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 );
Fwrite ($ filenum, $ data );
Fclose ($ filenum );
}
?>
92wcms.rar (692 B download: 17 times)
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB