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