PHP generated HTML meta and link tags have a blank line at the top of the body tag _php tips

Source: Internet
Author: User
Tags php script smarty template ultraedit
The HTML generated with the Smarty template in 1.php has a blank line at the top of the browser.

2. Use Firedebug to find meta and link tags in the body tag.

The WMAP running on this machine is OK, send to the remote server is iasp service, the above bug will appear.

Look at the source file, the same text. But when you save, you are prompted to encode the problem. It's utf-8.

Found on the Internet, is the Utf-8 BOM problem.

Workaround: Use UltraEdit32 to save the Smarty template file, which is a referenced template file (such as include Header,footer file), as a utf-8 file without a BOM.

Other supplementary notes:

The page uses the UTF8 code, the head and the tail uses the template to contain the document method, the result head and the tail end each to have an approximately 10px empty line, nothing.

The reason is all the use of UTF8 encoding, including documents, the final binary stream contains a number of UTF8 BOM tags, ie can not normally resolve the page contains multiple UTF8 BOM tag, directly replace the actual display of the return, resulting in a blank line, and Firefox does not have this problem.

Therefore, if the template contains a method containing more than one UTF8 document needs to be saved with UltraEdit Save as a feature selection UTF8 no BOM format saved.

In addition, if the Chinese page is in the HTML head tag, place the title tag in the <meta http-equiv= "Content-type" content= text/html; Charset=utf-8″/> will cause the page to be blank before.

So UTF8 pages should use standard order
Copy Code code as follows:

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8″/>
<meta http-equiv= "Content-language" content= "ZH-CN"/>
<meta name= "Robots" content= "Index,follow"/>
<meta name= "keywords" content= ""/>
<meta name= "desCription" content= ""/>
<meta name= "rating" content= "General"/>
<meta name= "Author" content= ""/>
<meta name= "Copyright" content= ""/>
<meta name= "generator" content= ""/>
<title></title>

BOM Header: \xef\xbb\xbf,php script 4, 5 is still ignoring the BOM, so direct output before parsing.

There is a specific description of this issue in this w3.org standard FAQ:

Www.w3.org/International/questions/qa-utf8-bom

Specifically as follows:

In the UCS code there is a char called ZERO WIDTH no-break Space, and its encoding is Feff. Fffe is not present in UCS char, so it should not appear in the actual transmission. UCS specification recommended that we transfer the byte stream before the transmission of char "ZERO WIDTH no-break space." This means that if the recipient receives the Feff, the byte stream is Big-endian, and if Fffe is received, it indicates that the byte stream is Little-endian. therefore char "ZERO WIDTH no-break Space" is also called BOM.

UTF-8 does not require a BOM to indicate byte order, but you can use a BOM to indicate how the encoding is encoded. Char "ZERO WIDTH no-break Space" UTF-8 code is the EF BB BF. So if the receiver receives the byte stream at the beginning of the EF BB BF, it will know that this is UTF-8 code.

Windows is an operation that uses a BOM to mark the encoding of a text document SYSTAM:WINDOWSXP Professional, default char set: Chinese

1) Notepad: You can automatically identify the UTF-8 encoded format document without a BOM, but you cannot control whether you add a BOM when you save the document, and if you save the document, the BOM is added uniformly.

2) EditPlus: Can not automatically identify the UTF-8 coding format document without BOM, when the document is saved, select UTF-8 format, will not write the BOM header on the document header.

3) UltraEdit: For char encoding is the most powerful, you can automatically identify with the BOM and without the BOM Utf-8 document (can be configured), save the time can be configured to choose whether to add a BOM.
(Notably, when you save a newly created document, you need to choose to save as Utf-8 no BOM format)

Later found that Notepad + + also for Utf-8 BOM support is better, recommended that you use.
Related Article

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.