Why is the layout affected by blank content on the top of the browser when previewing the PHP file and the solution?

Source: Internet
Author: User

During PHP file preparation, a blank line is displayed on the top of the browser when previewing the PHP file, which affects the page layout.

The BOM header is described as follows::

Generally, you can use the Notepad program that comes with Windows to write web programs. However, after you write or modify the code of the php Blog system, the following problems always occur during debugging:

-You cannot log in or log out;
-A blank line appears at the top of the page;
-An error warning is displayed on the top of the page;
-Other abnormal situations.

Cause Analysis:
Because UTF-8 encoding is used, the code is saved as UTF-8 encoding format after being written or modified. Although almost all text editing software can now display and edit UTF-8-encoded files, it is a pity that many of them are not doing well.

Similar to WINDOWS notepad and other software, when saving a file encoded in UTF-8, will insert three invisible characters at the beginning of the file (_ 0xEF _ 0xBB _ 0xBF, BOM -- Byte Order Mark ). It is a string of hidden characters, used for the notepad editor to identify whether the file is encoded in UTF-8. For general files, this will not cause any trouble. But for PHP, PHP did not consider the BOM issue during design, does not ignore the three characters at the beginning of the UTF-8-encoded file BOM, the BOM is used as a part of the Beginning body of the file. Because it must be in the <? Or <? The code after php is executed as PHP code, so the three characters will be output on the page. The display effect depends on the browser, which is generally a blank line or garbled code. Because these three characters exist at the beginning of html, even if the top padding of the page is set to 0, the whole web page cannot be placed close to the top of the browser. Due to the restriction of the COOKIE sending mechanism, the COOKIE cannot be sent to files whose names start with BOM (because PHP has already sent the file header before the COOKIE is sent ), therefore, the logon and logout functions are invalid. All functions dependent on cookies and sessions are invalid.

Solution:

When editing or changing any text files, you must use an editor without adding BOM. The editor in Linux should have no such problem. In WINDOWS, do not use notepad or other editors. The recommended editor is:
Editplus version 2.12 or later;
EmEditor;
UltraEdit (you need to cancel the related options of 'add BOM );
Dreamweaver (you need to cancel the related options of 'add BOM );
Notepad (to convert to UTF-8 without BOM) and so on.

If you want to cancel a file that has been added with BOM, you can use the editor above to save it again. (Editplus needs to be saved as gb first, then as UTF-8. Dreamweaver can cancel the "contain Unicode signature (BOM)" in the "Page attribute)

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.