PHP grammar learning notes

Source: Internet
Author: User
Tags echo d

I. php scriptCodeMark

The PHP script is the content included in a pair of special tags in the file. For example, ASP is "<% .... %> ", PHP can be viewed as" <?...?> ".

However, to adapt to XML standards to embed PHP into XML or XHTML, PHP does not recommend using short-format"<?...?>"However, we recommend that you use long format tags."<? PHP...?>"

In addition, the PHP code block supports the markup form of <script language = "php">... </SCRIPT>.

2. php instruction Separator

Each PHP statement needs to be separated by the Semicolon ";", but the PHP end mark "?>" Because it automatically implies a semicolon, you do not need to append the semicolon.

Therefore, the format of a PHP script is as follows:

<? PHP
/*
............;
............;
............;
............
*/
// Note that the last row can have no semicolon
?>

3. php comments

PHP multi-line comment using "/*... */"

Use "#" or "//" for a single line comment

4. php output

Use "<% =... %>" in ASP to quickly output a single row, or use "<% response. Write ("... ") %>"

Directly use "echo ()" or "Print ()" in PHP, for example:

<? PHP
Echo "";
Echo (B );
Echo ("C ");
Echo D;
?>

The output is "ABCD". All the above four types can be output normally.

However, in ASP, Especially echo "A"; and echo D; are output as strings themselves, which is impossible. Therefore, you need to understand the definition of PHP variables.

V. php Variables

Like ASP, PHP variables can be directly used without being defined first. Variable types are automatically generated when values are assigned.

All variables in PHP are added before the variable name."$"To show the difference.

<? PHP
$ A = "123 ";
Echo;
Echo $;
?>

Enter "A123"

6. The difference between single quotes and double quotes in PHP

<? PHP
$ A = "123 ";
Echo "$ ";
Echo '$ ';
?>

Output as"123 $Echo "$ A" outputs the value of variable A, while echo '$ a' outputs the string itself in single quotes.

<? PHP
$ A = "123 ";
Echo "$ '";
?>

The output is"123 '123'"Is not" 123 $ ". Although it is '$ A', the variable placed under double quotation marks is still replaced.

Therefore, we can conclude that:Variables in double quotation marks will be replaced..

The content in double quotation marks must be escaped and prefixed with "\", such as "\", "\ $", and "\". Therefore, if you enter "123 $ ",

<? PHP
$ A = "123 ";
Echo "$ A \ $ ";
?>

For example:

<? PHP
$ A = "123 ";
Echo "$ \"\\";
?>

Output as"123 $ "\".

Notes for transferring ASP to PHP:

1. The separator comma ";" is easy to forget to write.
2. Definition and use of variables.
3. single quotation marks and double quotation marks.

PHP manual download:
Http://www.php.net/download-docs.php

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.