Browser preview php file when the top appears blank influence layout analysis reason and solution _php skill
Source: Internet
Author: User
In the process of writing PHP files, it is found that when the browser preview php file, the top will appear a line of blank, affecting the layout of the page.
the explanation for the BOM header is as follows:
Typically, you can use a Notepad program that comes with a Windows system to write a Web page program, but when you write or modify the PHP blog system code, there are always the following questions:
– Cannot log in or log out;
– A blank appears at the top of the page;
– There is an error warning at the top of the page;
– Other abnormal situations.
Analyze the reason:
Because you use UTF-8 encoding, you save the code as a UTF-8 encoding after you write or modify it. While almost all text-editing software can now display and edit UTF-8-encoded files, it's a pity that many of these software do not perform well.
Software such as Notepad, which is a Windows UTF-8, inserts three invisible characters (_0xef _0xbb _0xbf, bom--byte order Mark) at the beginning of a file when you save a file encoded in the document. It is a string of hidden characters that allow editors such as Notepad to recognize whether the file is encoded in UTF-8. For general files, this does not cause any trouble. But for PHP, PHP is not considered in the design of the issue of the BOM, will not ignore the UTF-8 encoded file at the beginning of the BOM that three characters, will be the BOM as part of the beginning body of the file. Because the code that must be in the <?php or the following will be executed as PHP code, it will result in the output of these three characters on the page, the display effect will be to see the browser, is generally a blank line or a garbled. Because of the presence of these 3 characters at the beginning of HTML, even if the top padding of the page is set to 0, it is impossible to keep the entire page close to the front of the browser. Because of the limitations of the cookie delivery mechanism, a cookie cannot be delivered in a file that already has a BOM at the beginning of the file (because PHP has sent the file header before the cookie is sent), so the login and logout functions fail. All the functionality that relies on cookies and session implementations is invalid.
Solutions:
When editing or changing any text file, be sure to use an editor that does not randomly add a BOM. The editor under Linux should not have this problem. Under Windows, do not use editors such as Notepad. The recommended editors are:
EditPlus 2.12 version above;
EmEditor;
UltraEdit (need to cancel the ' Add BOM ' related option);
Dreamweaver (need to cancel the ' Add BOM ' related option);
Notepad (Need to "convert to UTF-8 without BOM") and so on.
For files that have already been added to the BOM, you can save them again with the above editor. (EditPlus need to be saved as GB first, then save as UTF-8.) Dreamweaver is canceled in page properties with Unicode signature (BOM)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service