Basic PHP syntax

Source: Internet
Author: User
Tags closing tag
PHP basic syntax preface

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

  • PHP tag
  • Separating from HTML
  • Command separator
  • Note
PHP tag

PHP script End:

 
  

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

PHP can also use short Tags ,But not encouraged. The short tag can be used only when the short opentag configuration command in php. ini is activated or the configuration option-enable-short-tags is used during PHP compilation.

If the file content isPure PHPCode, preferably inDelete the PHP end mark at the end of the file. This avoids accidental addition of spaces or line breaks after the PHP end mark, which may cause PHP to start to output these spaces, but the script does not have the intention to output at this time.

For example, the following is in a file. this file only has PHP code. do not add the parameter?> End ID:

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

Separating from HTML

Any content except the start and end tags will be ignored by the PHP parser, which allows the PHP file to have mixed content. PHP can be embedded into HTML documents, as shown in the following example:

 

This isgoingtobeignoredbyPHP anddisplayedbythebrowser.

This willalsobeignoredbyPHP anddisplayedbythebrowser.

Condition separation:

 
  
  
   This willshowif theexpressionistrue.
   Otherwise thiswillshow.
  

Command separator

Like the C language, PHP needs to end the command with a semicolon after each statement. The end mark in a PHP code segment implicitly represents a semicolon; the last line in a PHP code segment can end without a semicolon. If a new line is followed, the end mark of the code segment includes the end of the line.

 
  
  
  

Note

PHP supports comments of C, C ++, and Unix Shell (Perl style. For example:

 
  

You can use // or # comment a single line, and use/**/comment segment.

Conclusion

This article is just my notes on learning PHP! Of course, you are also welcome to leave a comment and ask for a quick guide. If you feel useful to yourself, you are welcome to study PHP, discuss PHP syntax knowledge, and practice PHP together.

Follow my PHP study group: 536643087

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.