PHP Basic Syntax

Source: Internet
Author: User
Tags closing tag learn php

Objective

The PHP script can be placed anywhere in the document. This article mainly includes the following content:

    • PHP tags
    • Detach from HTML
    • Instruction delimiter
    • Comments

PHP tags

PHP script to end with:

 
 
  

When parsing a file, PHP looks for the start and end tags, which tells PHP to start and stop parsing the code between the two. This parsing allows PHP to be embedded in a variety of different documents, and any part outside the start and end tags will be ignored by the PHP parser.

PHP also allows the use of short tags , but is discouraged . The short mark can only be used if the Opentag configuration directive in php.ini is activated or if the configuration option –enable-short-tags is used when compiling PHP.

If the file content is pure PHP code, it is best to remove the PHP end tag at the end of the file. This avoids having to accidentally add a space or line break after the PHP end tag, which causes PHP to start outputting these blanks, and there is no intention to output the script at this time.

For example, the following is in a file, this file only PHP code, at this time build justice do not add?> end identity:

 
 
  "; echo" test
"Echo" www.henishuo.com ";

Detach from HTML

Anything outside a pair of start and end tags is ignored by the PHP parser, which allows the PHP file to have mixed content. You can embed PHP into an HTML document, as shown in the following example:

This isgoingtobeignoredbyphp anddisplayedbythebrowser.

This willalsobeignoredbyphp anddisplayedbythebrowser.

Conditional separation:

 
 
   
 
   
 
    This willshowif theexpressionistrue.
 
    Otherwise Thiswillshow.
 
  

Instruction delimiter

Like the C language, PHP needs to end the instruction with a semicolon after each statement. An end tag in a PHP code implies a semicolon; the last line in a PHP snippet can end without a semicolon. If there are new rows later, the end tag of the snippet contains the end of the line.

 
 
   
 
   
 
  

Comments

PHP supports C, C + +, Unix shell style (Perl style) annotations. For example:

 
 
  

You can use//or #注释单行, you can use the/**/comment segment.

Written in the last

This article is only the author to learn PHP notes! Of course, also welcome the master message, to guide the accelerated method. If you feel that they are also useful to you, you are welcome to learn PHP together, discuss PHP grammar knowledge, practice PHP together.

Follow me

PHP Learning Exchange Group: 536643087

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