The operating environment of this article: Windows 10 system, PHP8.1.3 version, Dell G3 computer.
The PHP start tag is a special syntax structure used to indicate the beginning of PHP code. It tells the parser that the following code should be interpreted as PHP code, not ordinary HTML or other types of code. There are several different forms of PHP start tags, and the contents of each form are described in detail below.
Short tag form ()
The short tag form is the most common and simplest form of PHP start tag. It consists of a less than sign (<) and a question mark (?), which can be followed by a space or newline character. Its syntax is as follows:
In the short tag form, the PHP code must be in between. This form of opening tag is enabled by default in all versions of PHP, but may be disabled in some cases.
Short tag form (=)
The short tag form can also be used to output the value of a variable or expression. It consists of a less than sign (<), a question mark (?) and an equal sign (=). Its syntax is as follows:
In this example, $variable is a variable that contains the content to be output. This form of opening tag is enabled by default in all versions of PHP, but may be disabled in some cases.
Full tag form (
The full tag form is a longer start tag form, consisting of a less than sign (<), a It consists of a question mark (?) and the letter p (p), which can be followed by a space or a newline character. Its syntax is as follows:
The full tag form of the opening tag is enabled by default in all versions of PHP and is not affected by disabling it.
Short tag form (<%)
The short tag form can also use tags similar to ASP. It consists of a less than sign (<) and a percent sign (%). This form of opening tag was introduced in PHP version 5.4.0 and is enabled by default. However, it was removed in PHP version 7.0.0 and is therefore deprecated.
It should be noted that in order to ensure the portability and compatibility of the code, it is recommended to always use the full tag form (
Summary
There are many forms of PHP start tags, including short tag forms () and (=), full tag forms (< ?php) and the removed short form of the tag (<%). It is recommended to always use the full markup form (
The above is the detailed content of What are the contents of the php start tag?. For more information, please follow other related articles on the PHP Chinese website!