Cause:
Utf8 encoding solves the problem of empty rows before a webpage contains files
Http://www.cnblogs.com/qiantuwuliang/archive/2010/10/29/1864209.html
Code
<? PHP
If (isset ($ _ Get ['dir']) {// sets the 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.k686.com> http://www.k686.com </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 );
}
?>
Save it as a PHP file and put it under the root directory of the website. You can traverse the folder and clear the BOM automatically. This file is absolutely secure. For more information about the test Purpose, see
Put it in the root directory of the website, and then execute it. It will traverse all the files.
Like http://www.baidu.com/checkbom.php
You can also specify the directory for execution.
Like http://www.baidu.com/checkbom.php? Dir = html