Some basic knowledge about PHP for beginners

Source: Internet
Author: User
Tags echo d php for beginners

I. PHP script code mark
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 the use of "<?...?>" in short format ", We recommend that you mark "<? 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:

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:
The output is "abcd". All the above four types can be output normally.
However, in ASP, especially echo "a"; and echo d;, both 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.
Various variables in PHP Add "$" before the variable name to show the difference.
Enter "a123"

6. The difference between single quotes and double quotes in PHP 
The output is "123 $ a", where echo "$ a" outputs the value of variable a, while echo '$ a' outputs the string itself in single quotes.
The output value "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, while those in single quotation marks will not be replaced.
The content in double quotation marks must be escaped and prefixed with "\", such as "\", "\ $", and "\". Therefore, if you enter "123 $ ",
For example:
The output is "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.

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.