Empty line workaround in PHP template

Source: Internet
Author: User
Tags format character set contains copy empty header php template ultraedit
In the local also resolved, but upload to the server still have empty line, engaged in a morning, are fast collapse, and finally decided to find a way to solve their own, after a few hours of groping finally have a perfect solution.
Using PHP display buffer display principle, successfully removed
Add a line of Ob_start () to the head of PHP; Then the template is displayed before adding a ob_end_clean (); Add a Ob_end_flush () after the template display;
This solves the problem and now gives the overall structure instance code:
Copy CodeThe code is as follows:
<?php
Ob_start (); PHP logical Operation here
Ob_end_clean (); Display here for PHP templates
Ob_end_flush ();
?>


other Netizen's supplement:
In the development has not been able to solve a problem, the collection
The page uses the UTF8 code, the head and the tail uses the method which the template contains the file, the result head and the tail end each to have more than one 10px empty line, nothing.
The reason is all the use of UTF8 encoding, including files, 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, which led to a blank line, and Firefox does not have this problem.
Therefore, if the template contains a method containing multiple UTF8 files need to save with UltraEdit saved 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 CodeThe code is 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,PHP4, 5 still ignore the BOM, so the direct output before parsing.
There is a specific description of this issue in this w3.org standard FAQ:

Http://www.w3.org/International/questions/qa-utf8-bom

Specifically as follows:

In the UCS code there is a character called ZERO WIDTH No-break Space, and its encoding is Feff. Fffe is not present in UCS, so it should not appear in the actual transmission. UCS specification recommended that we transfer the byte stream before the transmission of the character "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, the character "ZERO WIDTH No-break Space" is also called the 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. The character "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 the operating system that uses a BOM to mark the encoding of a text file: Windows XPProfessional, default character set: Chinese

1) Notepad: You can automatically identify the Utf-8 code format file without a BOM, but you can not control whether to add a BOM when you save the file, if you save the file, you will add a unified BOM.

2) EditPlus: Can not automatically identify the UTF-8 coding format file without a BOM, file save, select UTF-8 format, will not be in the file header write BOM header.

3) UltraEdit: For character encoding is the most powerful, you can automatically identify with the BOM and without the BOM Utf-8 file (can be configured), save the time can be configured to choose whether to add a BOM.

(Notably, you need to choose to save as Utf-8 no BOM format when saving a newly created file)

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



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.