PHP closed label output extra empty exercise XML page display error handling

Source: Internet
Author: User
Tags cdata closing tag
In the official PHP documentation, it has been noted that it is best not to end up adding?> end tags. But our programming habits and the use of the IDE will be for me
We automatically set up PHP end tag?>. This tag is used under normal circumstances without affecting the operation of the program. Especially in the early PhP4, this
Improper use of the tag does not affect the final output. But I recently encountered a problem where the PHP script end tag shone as a page that could not be displayed.
First WAP is the final output of the XML file, and if there is a problem with the XML file format, the results cannot be displayed. During multiple checks the output is not found
Problem, the same code is displayed on another test machine without problems. With Firebug view, the final output

The main reason, through the Firebug analysis, can be found in the output XML before the empty line, the empty line as XML output is not normal, find all the original file and there is no output blank line or similar function statements. With Ob_clean-line debugging, it was found that after one of the files was loaded, the output had a blank line and the final discovery was that there were two blank lines after the end of the php file?>. Remove the blank line and the problem resolution output is normal.
The reason, the search for relevant information on the Internet, CodeIgniter Development specification gives the following explanations:
PHP closed Tag "?>" in PHP for PHP parser is optional. However, if you use a closed tag, any space behind the closed tag by a developer, user, or FTP application may cause extra output, PHP errors, output that cannot be displayed, and blank pages. Therefore, all PHP files should omit this PHP closed tag, and insert a note to indicate that this is the file's bottom and locate the file in the relative path of the application. This will help you to make sure that the document is over and not truncated.

The wrong wording incorrect<?php echo "Here's my code!"; >//correct wording correct:<?php echo "Here's my code!";

Demo:

Test.php<?phpheader ("Content-type:text/xml"); include_once (' sys_common.php '); Echo ' <?xml version= ' 1.0 " Encoding= "UTF-8"? ><rss version= "2.0" ><channel><title><! [cdata[Test]]></title><link><! [cdata[http://baidu.com]]></link><description><! [cdata[test blank line output]]></description><language><! [cdata[zh-cn]]></language><pubdate><! [Cdata[18.11.2016 14:54:02]]></pubdate><lastbuilddate><! [cdata[18.11.2016 14:54:02]]></lastbuilddate></channel></rss> ';//exit;

System files that need to be introduced sys_common.php

<?php  //do someing  //Note: This closing tag needs to be removed, so the output XML will not go wrong when the top is introduced.  //?>

OK, find the introduction file, remove the closed tag on the ok!

  • 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.