php simple Syntax One, PHP script code tag
PHP script is a special tag in the file included content, such as ASP is "<%....%>", PHP can be seen as "<?...? > ".
However, in order to adapt the XML standard to embed PHP into XML or XHTML, PHP does not recommend the use of short-form "<?...? > "and recommended long format tag" <? php ...? > "
In addition, the PHP code block also supports the form of markup.
PHP simple Syntax Two, PHP instruction delimiter
Each statement in PHP needs to be separated by a semicolon ";", but for the PHP end tag "?>", there is no need to append semicolons because it automatically implies a semicolon.
Therefore, the format of a PHP script can be as follows:
- < ? PHP
- Note that the last line can have no semicolon
- ?>
PHP simple Syntax three, PHP comments
PHP Multi-line comments using ""
Single-line comment using "#" or "//"
PHP simple syntax four, PHP output
Use the "<%=...%>" Quick output line in ASP, or use "<%response.write (...")%> "
Use "echo ()" or "print ()" Directly in PHP, such as:
- < ? PHP
- echo "a";
- Echo (b);
- Echo ("C");
- Echo D;
- ?>
The output is "ABCD", the above four kinds can be output normally.
But this is in ASP, especially echo "a"; and Echo D; is not possible to export to the string itself. This requires understanding the variable definition of PHP.
PHP simple Syntax five, PHP variables
Like ASP, PHP variables can be used without first defining them. For the type of the variable, it is automatically generated when the value is assigned.
Various variables in PHP are preceded by the variable name with "$" to differentiate.
- < ? PHP
- $ a = "123" ;
- echo A;
- echo $a;
- ?>
Enter as "A123"
PHP simple Syntax six, single and double quotes in PHP
- < ? PHP
- $ a = "123" ;
- echo "$a";
- echo ' $a ';
- ?>
The output is "123$a", where echo "$a" outputs the value of variable A, and echo ' $a ' outputs the string itself in single quotation marks.
- < ? PHP
- $ a = "123" ;
- echo "$a ' $a '";
- ?>
The output as "123 ' 123" is not "123$a". Although it is ' $a ', the variable is replaced with double quotes.
Therefore, it can be concluded that as long as the variables in the contents of the double quotation marks are substituted, the single quotation marks do not make any substitution.
The contents of the double quotation mark should be escaped, using "" prefix, for example "", "$", "" ". So to enter "123$a";
- < ? PHP
- $ a = "123" ;
- echo "$a $ A";
- ?>
Another example:
- < ? PHP
- $ a = "123" ;
- echo "$a $ A" ";
- ?>
The output is "123$a".
ASP transfer PHP needs to note:
1, delimiter comma ";" Easy to forget to write.
2, the definition and use of variables.
3, the use of single and double quotation marks.
This is the introduction of PHP simple syntax, hoping to deepen the reader's understanding of the PHP language.
http://www.bkjia.com/PHPjc/446241.html www.bkjia.com true http://www.bkjia.com/PHPjc/446241.html techarticle PHP simple Syntax One, PHP script code markup PHP script is a file in a pair of special tags included in the content, such as ASP is%....%,php can be seen as?...?。 In order to adapt the XML standard however to be ...