The reference file refers to the blank lines caused by the reference of other files by include and require_once.
This is actually after you use notepad to edit the UTF-8 file, although you still save as UTF-8 format, but the system will automatically add two bom labels to the file, but ie can only ignore one, the other is a blank line.
Solution:
Do not use notepad to edit UTF-8 files, use other tools, such as Dreamw, EmEditor, Visual Studio 2008 and other editing tools to edit UTF-8 files and save.
After editing the two sites in Notepad, there is a blank line on the top. At first, I thought it was a css setting problem and the result was caused by bom marking.
Another way is to use a php function if you use a large number of files.
Copy the following code to a PHP file and run it in the directory where you need to clear the BOM header. Then, you can batch clear the blank first line of PHP, which is awesome.
| The code is as follows: |
Copy 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. </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 );
}
?> |