Simple generalization of the difference between single and double quotes in a PHP string _php tips

Source: Internet
Author: User

Today, a friend asked, the next difference, by the way review.

Single quotes differ from double quotes:

    • The fields inside the double quotes are interpreted by the compiler and then exported as HTML code.
    • ' Single quotes inside without explanation, direct output.
    • Single quotes parse more quickly than double quotes.
    • Single quotes support \ Escape characters, double quotes support more escape characters.
$hello = 3;
echo "Hello is $hello"; Print Result: Hello is 3 
echo ' Hello is $hello ';//print Result: Hello is $hello 
echo "Hello is $hello \ n";//Print Result: Hello is 2 (line wrap at the same time) 
Echo ' Hello is $hello \ n '; Print Result: Hello is $hello \ n

Ps:
today, I saw a foreigner mention the single quotation mark of PHP, which mentions the interesting things, excerpt as follows:
Which said that installed PHP expansion Vulcan Logic disassembler, you can see the middle code generated by PHP,
The first is:

echo "This is a string"; 

Will turn into:

ECHO    ' This is a string ' 

and

Echo ' is a string '; 

It becomes

 ECHO    ' This is a string ' 

, is the same
If it is

echo "This is a $variable"; 

The opcode generated by PHP is

INIT STRING ~0 

2 add_string  ~0 ~0 ' This ' 

3 add_string ~0 ~0  ' 

4 add_string ~0 ~0 ' is  ' 

5 A dd_string  ~0 ~0 ' 

6 add_string  ~0 ~0 ' a ' 7 add_string ~0 ~0 ' " 

8 add_var    ~0 ~0!0
   9 ECHO      ~0 

and

echo "This is a". $variable; 

It will become

CONCAT    ~0 ' This is a '!0 

2 ECHO      ~0 

You can see, the speed is much faster, use. Connection words

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.