Problem: Background as follows, direct view backstage, the source code exists, but it is not displayed.
Workaround: This is because the UTF-8 encoded HTML file contains the BOM, you can use a special program to remove the BOM, view here, you can also delete this HTML file, re-establish. Note that the source code can be copied in the other UTF8 editor, such as EditPlus, and then re-established
BOM information is a string of hidden characters at the beginning of a file that allows some editors to recognize that this is a UTF-8 encoded file. However, PHP reads these characters when reading a file, which creates an issue that contains some unrecognized characters at the beginning of the file.
For example, in the UTF-8 format to save the generated image of the PHP file, because the file header hidden BOM information is also issued, resulting in the resulting image data is not recognized by the browser.
To detect whether a UTF-8 file contains BOM information, is to detect the beginning of the word three characters, whether it is 0xEF, 0xBB, 0xBF. Under this applet, the user iterates through all the files in a directory and detects if the BOM is added.
<? Php
This file is used to quickly test whether UTF8 encoded files are added to the BOM and can be automatically removed
by Bob Shen
$basedir = "."; Modify this behavior to detect the directory where the point represents the current directory
$auto = 1; Whether the discovered BOM information is automatically removed. 1 for Yes, 0 for No.
This file is used to quickly test whether UTF8 encoded files are added to the BOM and can be automatically removed
by Bob Shen
$basedir = "."; Modify this behavior to detect the directory where the point represents the current directory
$auto = 1; Whether the discovered BOM information is automatically removed. 1 for Yes, 0 for No.
Do not change the following
if ($dh = Opendir ($basedir)) {
while (($file = Readdir ($DH))!== false) {
if ($file! = '. ' && $file! = ': ' &&!is_dir ($basedir. " /". $file)" echo "FileName: $file". Checkbom ("$basedir/$file"). "<br>";
}
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);
}
Save the above code as del_bom.php, and modify the directory that needs to be instrumented to run. This may help to detect which file with the BOM information results in a blank space at the beginning of all pages.
Frameset Frame When template displays Blank solution