The relationship and difference between PHP single and double quotes

Source: Internet
Author: User
today we directly through a few practical small cases to explain the difference, we observe carefully!

//double quotation mark knowledge explanation

//This is a mistake because it will treat hello as a double-quote character, and world will be a character you don't know.

$str 1 = "Hello" World "".
';

//correct notation: the world with double quotes should be added with the escape character \ So there will be no boundary ambiguity
$str 1 = "Hello \" world\ "".
';
Echo $str 1;
$str 2 = "Hello \n\r\t world".
'; //\n\r: NewLine carriage return, double quotation marks can be parsed
Echo $str 2;
$str 3 = "Hello $str 1". '
'; //At this point the system will parse the $STR1 into a variable, it will call $STR1
Echo $str 3;
$str 4 = "Hello \ $str 1"; After the //is compliant with the escape character, the system will treat $str1 as a normal string and no longer a variable
Echo $STR 4;
//Single quotation mark knowledge explanation
$str 1 = ' Hello \n\r\t world '. '
'; //Single quotation mark cannot resolve recognition \n\r\t, it will be output directly as normal character
echo $str 1;
$str 2 = ' Hello $str 1 '; //single quotation marks can not resolve the identification $ symbol, will be directly $str1 when the normal character output
echo $str 2;
single-double quotation mark mixed explanation, get 3 conclusion:

1. Single quotes cannot be escaped too much, only \ \ ', and double quotes can be escaped \ \ \ \ \ \ \ \t
2. Single quotation marks cannot resolve the $ variable character, whereas double quotes can be
3. Because single quotes do not have to be considered in many cases, single quotes are faster than double quotes!

I believe that through tonight's analysis, everyone later on in PHP single double quotes, there will be no doubt about it! If everyone thinks it's good, feel free to

A little reward , thank you!


The above describes the PHP single double quotation mark relationship and differences, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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