PHP script is a pair of special tags in the file included content, such as ASP is "<%....%>", PHP can be seen as "<?...? > ".
However, in order to accommodate XML standards to embed PHP in XML or XHTML, PHP does not recommend using short format "<?...? > ", and it is recommended that you use long format tags
"<?php ...?" > "
In addition, the PHP code block also supports the <script language= "php" >...</script> tag form.
Two, PHP instruction separator
Each statement in PHP needs to be separated by a semicolon ";", but for the PHP closing tag "?>", it automatically implies a semicolon, so there is no need to append a semicolon.
So, the format of a PHP script can be as follows:
<?php
/*
............ ;
............ ;
............ ;
............
*/
Note that the last line can have no semicolon
?>
Three, PHP comments
PHP Multiline Annotations Use the "/* ... *"
Single-line comments Use "#" or "//"
four, the output of PHP
In ASP, use the "<%=...%>" fast output line, 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" and the above four types are normally output.
but this is in the ASP, especially echo "a"; and Echo D; is output to the string itself, and is not possible. This requires understanding the variable definition of PHP.
Five, PHP variables
Like the ASP, PHP variables can be used without first defining them directly. For the type of the variable, automatically generated when the value is assigned.
Various variables in PHP are preceded by the variable name
"$"To show the difference.
<?php
$a = "123";
echo A;
echo $a;
?>
Enter as "A123"
six, the single and double quotes in PHP
<?php
$a = "123";
echo "$a";
echo ' $a ';
?>
Output as "
123$a, where echo "$a" outputs the value of variable A, and echo ' $a ' outputs the string itself in single quotes.
<?php
$a = "123";
echo "$a ' $a '";
?>
The output is "
123 ' 123 '"Is not" 123$a ". Although it is ' $a ', the variable is replaced with double quotes.
So, you can draw the following:
as long as the variables in the contents of the double quotes are substituted, and the single quotes are not replaced。
The contents of the double quotes should be escaped using the "\" prefix, such as "\", "\$", "\". So to enter "123$a";
<?php
$a = "123";
echo "$a \ $a";
?>
Another example:
<?php
$a = "123";
echo "$a \ $a \ \";
?>
Output as "
123$a "\”。
ASP transfer PHP need to note:
1, delimiter comma ";" Easy to forget to write.
2, the definition and use of variables.
3, the use of single and double quotes.
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.