A detailed introduction to PHP simple Syntax _php tutorial

Source: Internet
Author: User
Tags code tag echo d
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:

 
  
  
  1. < ? PHP
  2. Note that the last line can have no semicolon
  3. ?>

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:

 
  
  
  1. < ? PHP
  2. echo "a";
  3. Echo (b);
  4. Echo ("C");
  5. Echo D;
  6. ?>

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.

 
  
  
  1. < ? PHP
  2. $ a = "123" ;
  3. echo A;
  4. echo $a;
  5. ?>

Enter as "A123"

PHP simple Syntax six, single and double quotes in PHP

 
  
  
  1. < ? PHP
  2. $ a = "123" ;
  3. echo "$a";
  4. echo ' $a ';
  5. ?>

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.

 
  
  
  1. < ? PHP
  2. $ a = "123" ;
  3. echo "$a ' $a '";
  4. ?>

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";

 
  
  
  1. < ? PHP
  2. $ a = "123" ;
  3. echo "$a $ A";
  4. ?>

Another example:

 
  
  
  1. < ? PHP
  2. $ a = "123" ;
  3. echo "$a $ A" ";
  4. ?>

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 ...

  • 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.