Under what circumstances can not write PHP's closed tag "?>", do not write PHP
In some PHP projects we often see that some PHP files in the code is only the start tag, but not the end tag, then under what circumstances can not write the end tag, and under what circumstances must be written?
Let's take a look at 2 examples first:
The following code will work:
<?php Echo 123456;
The following code will error:
<?php Echo 123456; Abc
Cause Analysis:
The former is pure PHP code, you can not write the end tag, and do not recommend to write the end tag, the latter in addition to PHP code, and HTML code, you must write the end tag.
So why not recommend the former to write the end tag?
Because when the PHP end tag is not written, the default from the start tag is PHP code, if there are other code, it will be an error. PHP can only run the script inside the PHP tag, all characters outside the script, including the space you can't see or the carriage return, the tab symbol, will be response to the client as the output, which may produce unexpected things . For example, the file is used in the header function, the file also contains another file, and the file contained in the PHP tag has null characters, this time will be reported to the header already send error. We look at some of the Web page source code to see the beginning of a lot of space and newline, that is because of this cause.
Solution Recommendations:
library files, or some class files, and so on only pure PHP code files are not recommended to add the end tag .
It is believed that this article has certain reference value to the PHP program design of everybody.
Why does PHP sometimes not write closed tag terminator?
Find some information, everyone on the PHP closed tag summary is as follows: Benefits: If this is a program that someone else contains, without this terminator, can reduce a lot of problems, such as: header, Setcookie, session_start These actions can not have output, What if you're not careful? After the addition of invisible characters (extra space, line breaks) and other broken page display, will report the header already sent error, do not write the words will not have this problem. Alternatively, you can move the cursor directly to the end and then program. Cons: In Dreamweaver view mode, it's a mess. The official explanation for the PHP closing tag is: PHP closed tag? PHP parser is optional in PHP. 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. Improper:
Why some people's PHP files do not write the end tag of the PHP language-technical questions
If the file is not executed alone, that is, it must be included in other files, it is recommended not to write the end tag, not not recommended, but has its special meaning
http://www.bkjia.com/PHPjc/871104.html www.bkjia.com true http://www.bkjia.com/PHPjc/871104.html techarticle under what circumstances can not write the PHP closed tag "?", do not write PHP in some PHP projects we often see some PHP files in the code is only the start tag, but not the end tag ...