Under what circumstances can I leave the PHP closed tag "? & Gt; ", do not write php_PHP tutorial-php Tutorial

Source: Internet
Author: User
Under what circumstances can I leave the PHP closed tag "? & Amp; gt; ", no php. Under what circumstances can I leave the PHP closed tag "?"? Without writing php, in some PHP projects, we often see that some PHP files only have the start tag, but without the end tag, you can leave the php closed tag "?> ", Leave php empty

In some PHP projects, we often see that the code in some PHP files only has the start tag but not the end tag. under what circumstances can this end tag be left blank, under what circumstances must I write?

Let's look at two examples:

The following code runs properly:

<?php  echo 123456;

The following code reports an error:

<?php  echo 123456;  

abc

Cause analysis:
The former is a pure php code. you can neither write the end tag nor the end tag. in addition to the php code and html code, the latter must write the end tag.

So why is it not recommended to write the end tag for the former?
When you do not write the php end tag, the default start tag is followed by the php code. if there is other code, an error is reported. Php can only run scripts in php labels. all characters outside the script, including invisible spaces, carriage return, and tabulation symbols, are returned to the client as output content, in this way, unexpected things may occur. For example, if the file uses the header function, this file also contains another file, and the php tag of the included file contains empty characters, the header already send error will be reported at this time. We can check the source code of some web pages and see many spaces and line breaks at the beginning, which is caused by this reason.

Solution suggestions:

The end tag is not recommended for files with only php code, such as library files or some class files.

I believe this article has some reference value for everyone's PHP program design.


Why sometimes php does not write a closed tag Terminator?

After looking for some information, we can summarize the PHP closed labels as follows: Advantages: if this is a program included by others, without this Terminator, it can reduce many problems, such: header, setcookie, and session_start cannot be output before these actions? When invisible characters (extra spaces and line breaks) are added to the backend to destroy the page display, the Header already sent error will be reported. if you do not write the Header, this problem will not occur. In addition, you can directly move the cursor to the end and then program. Disadvantage: a mess in dreamweaver view mode. The official explanation for PHP closed tags is: PHP closed tags? PHP analyzer is optional in PHP. However, if you use closed tags, any developer, user, or the spaces after inserting the closed tag in the FTP application may cause redundant output, php errors, and subsequent output failures or blank pages. Therefore, all php files should omit this php closed tag and insert a comment to indicate that this is the bottom of the file and locate the relative path of the file in this application. This will help you determine that the file has been ended rather than deleted. Improper:

Why does some people leave the PHP language end tag for their PHP files?-Technical Q &

If the file is not executed independently, that is to say, it is not recommended to write the end tag when it must be included in other files. it is not recommended, but has special significance.
 

Success, Without writing php, in some PHP projects, we often see that some php files only have the start tag, but not the end tag...

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.