Php template appears empty line solution _ PHP-php Tutorial
Source: Internet
Author: User
Recently written in php, inexplicable browser header more than a line of blank lines, search on the Internet, roughly all the files saved to non-BOM UTF-8 format in the local also solved, however, I still have time to upload files to the server. after a morning, I almost crashed. Finally, I decided to solve the problem myself. after several hours of exploration, I finally got a perfect solution.
The display principle of the buffer in php is used and removed successfully.
Add an ob_start () line to the header of php; then add ob_end_clean () before the template display; add ob_end_flush () after the template display ();
The problem is solved, and the overall structure of the instance code is now given:
The code is as follows:
Ob_start (); // php logic operation here
Ob_end_clean (); // The php template is displayed here.
Ob_end_flush ();
?>
Supplemented by other netizens: A problem that cannot be solved during development.
The page is UTF-8 encoded, and the template containing files is used in the header and tail. as a result, each header and tail have a blank line of about 10 PX, and there is nothing.
The reason is that all files are UTF-8 encoded. when files are included, the final binary stream contains multiple utf8 BOM tags. IE cannot parse pages containing multiple UTF8 BOM tags normally, directly replace it with the actual displayed carriage return, which leads to a blank line, but firefox does not.
Therefore, if the template contains multiple utf8 files, use the ultraedit save as function to select utf8 without bom format.
In addition, if the Chinese page places the title tag in the html head tag The page is blank.
Therefore, standard order should be used for utf8 pages
The code is as follows:
BOM header: \ xEF \ xBB \ xBF, PHP4, and 5 are still ignored. Therefore, the BOM is output directly before resolution.
This w3.org standard FAQ provides a special description of this issue:
There is a character named "zero width no-break space" in the UCS encoding, and its encoding is FEFF. FFFE does not exist in the UCS, so it should not appear in actual transmission. We recommend that you first transmit the character "zero width no-break space" before transmitting the byte stream ". In this way, if the receiver receives FEFF, it indicates that the byte stream is Big-Endian; if it receives FFFE, it indicates that the byte stream is Little-Endian. Therefore, the character "zero width no-break space" is also called BOM.
The UTF-8 does not need BOM to indicate the byte order, but BOM can be used to indicate the encoding method. The UTF-8 code for the character "zero width no-break space" is ef bb bf. So if the receiver receives a byte stream starting with ef bb bf, it will know that this is UTF-8 encoding.
Windows is the operating system that uses BOM to mark the encoding method of text files: WindowsXP Professional, default character set: Chinese
1) notepad: it can automatically identify UTF-8 encoded files without bom, but it cannot control whether to add bom when saving the file. if the file is saved, the bom will be added in a unified manner.
2) editplus: can not automatically identify the UTF-8 encoding format file without bom, when saving the file, select the UTF-8 format, will not write BOM header in the file header.
3) UltraEdit: it is the most powerful character encoding function. it can automatically identify the UTF-8 files with and without bom (which can be configured). During saving, you can select whether to add bom through configuration.
(Note that when saving a new file, you must save it as UTF-8 no bom)
Later, we found that Notepad ++ also provides better support for the UTF-8 bom. we recommend that you use it.
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