About PHP language tags, instruction separators, comment explanations

Source: Internet
Author: User
Tags closing tag php programming
PHP language tags, instruction separators, and annotations play an important role in PHP programming.

1. PHP Start and end flags

PHP ends with a?> representation. Most embedded scripting languages are embedded in HTML such as CSS, ASP, JSP, JS, and so on.

When PHP parses a file, it looks for the start and end flags, telling PHP to start and stop explaining the code. When PHP touches the end flag, it simply outputs the contents as it is, so you can embed any number of PHP flags in an HTML document.

# #下边内容不重要, understand.

In addition to the above PHP start and end flags, but also, <%%>, <script language= "PHP" ></script>, etc., in the page embedded in the variable, also can use, and <script Language= "PHP" ></script> is always available, others can be switched on in php.ini.

It is worth noting that:

1, in the php.ini open asp_tags, in order to use. <%%> is no longer supported in PHP7, it is not recommended.

2, will interfere with the XML document declaration, is generally disabled, you can open the Short_open_tag configuration in php.ini, or in the PHP compile to add the –short_open_tag option before you can use. It is not recommended.

3. It is strongly recommended to use the standard start-end sign.

4, only the file containing PHP script, does not allow the end of the flag?> exists, this can prevent the end is accidentally injected, resulting in the use of header (), Setcookie (), Session_Start () and other functions to set the head information is a failure. Cause: When a php file loads another php file, what if the end of the file flag? > There is a space "" in the back, then an error occurs after loading the file with a function that sets the header information. Because these functions do not allow spaces to appear before. In addition, the script with the end sign will output the end flag as is. > The space behind it.

The space inside the PHP tag is automatically ignored when interpreted.

Eg: file a.php <!--? php//Anycode here?--> file b.php<!--? phpob_start (); Include_once ' a.php '; $con = ob_get_contents ();//This function returns the contents of the output buffer, or false if the output buffer is invalid. Ob_clean () var_dump ($con)?-->

Executing the b.php file will output string (4) "".

2. Instruction Delimiter semicolon

PHP after each instruction need to end the English semicolon, the end of the PHP flag? > implicitly represents a semicolon, so the last line in a PHP code can end without a semicolon.

eg1:<!--? php echo "123"?-->//The last closing tag implies a semicolon, so here you can end eg2:<!--? php        echo "123" without a semicolon;//This is a PHP directive, Must be followed by a semicolon to indicate the end </pre-->

3. Program Notes

Annotations are a fairly important part of programming. The content of the comment will be ignored by the Web server engine and will not be interpreted for execution. Note Be sure to write to the top or right of the code, and never write it behind the code.

1) The role of annotations:

① describes the role of the Code, to provide help for reading, whether it is themselves or others, to facilitate future maintenance.

② comments at the time to feel inappropriate code, easy to use later, open the comments can

③ for commissioning

2) Comment Classification:

① a single-line comment. There are two main types, namely "//" and "#".

② multiple lines of comment. Start with "/*" and "* *" end. Multiline comments cannot nest multiple lines of comments, but single-line comments and multiline comments can be included with each other.

EG1: The following is an example of a multiline comment nested multiple lines comment error. <!--? php/    *    echo 123;/* Nested multiple lines of comments inside a multiline comment */    */</pre-->

3) Note considerations

Comments will only comment out the content before the end flag, and will not comment out the end flag "?>"

Eg: the "?>" below will not be commented out <!--? php    echo 123;//?-->

4) Specification Notes

The Phpdocumentor tool, which prompts you to standardize annotations, allows you to quickly generate API documentation with features such as cross-referencing, indexing, and so on. Multiline annotations generally end with "/**" starting with "*/". There are @param in our common annotations that are probably also because of the tool, although you are not using the tool.

Eg: multi-line Comment <!--? php    /**     * Set schedule information for current request     * @access public     * @param array|string  $dispatch Dispatch information     * @param string        $type dispatch type     * @return void     *    /public static function dispatch ($dispatch, $type = ' MoD Ule ') {         ...    } </pre-->

This article explains the PHP language tags, instruction separators, comments related content, more relevant knowledge, please pay attention to the PHP Chinese web.

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.