Close contact PHP PHP Grammar Learning Note 1

Source: Internet
Author: User
Tags code tag echo d
One, PHP script code tag
PHP script is a special tag in the file included in the 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 using the short format " ", and we recommend using long format tags. ”
In addition, the PHP code block also supports the form of markup.
Second, 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:
/*
............ ;
............ ;
............ ;
............
*/
Note that the last line can have no semicolon
?>

Third, PHP comments
PHP Multi-line comments use "/* ... */"
Single-line comment using "#" or "//"
Four, the output of PHP
Use the "<%=...%>" Quick output line in ASP, or use "<%response.write (...")%> "
Use "echo ()" or "print ()" Directly in PHP, such as:
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.
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.
$a = "123";
echo A;
echo $a;
?>

Enter as "A123"
Six, single and double quotes in 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.
$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 quotes should be escaped, using the "\" prefix, such as "\ \", "\$", "\". So to enter "123$a";
$a = "123";
echo "$a \ $a";
?>

Another example:
$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.

The above describes the intimate contact PHP PHP Grammar study Note 1, including the content of the article, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.