PHP single double quote difference, PHP double quotation mark Difference _php Tutorial

Source: Internet
Author: User

PHP single double quote difference, PHP double quote Difference


in PHP, the definition of a string can use single quotation marks ' ' in English , you can also use double quotes " " in English .

However, you must use the same single or double quotation mark to define a string, such as: 'Hello World" and "Hello World' an illegal string definition.

What's the difference between a single quote and a double quote?

PHP allows us to include it directly in a double quote string 字串变量 .

The contents of a single quote string are always considered ordinary characters, so the content in single quotes is not escaped more efficiently.

Like what:

$str = ' Hello '; echo "str is $STR"; Operation Result: STR is Helloecho ' str is $str '; Operation Result: STR is $STR

In PHP, the variables ($var) and special characters (\ r \ n) in double quotes are escaped, and the content in single quotes is not escaped (so it is more efficient).
Use on the words,
I used to like to write in a SQL string like this $sql = "SELECT * FROM table WHERE id = $id", so that the $id inside can be escaped, single quotes will not work.

There is no difference between single and double quotes in JavaScript, as long as paired use is OK.
I use single quotes in JavaScript mostly because JavaScript deals more with HTML, and you don't need to escape the quotes of attributes in HTML when outputting HTML fragments.
In short, see the actual situation to use, how convenient how to use.





http://www.bkjia.com/PHPjc/962878.html www.bkjia.com true http://www.bkjia.com/PHPjc/962878.html techarticle PHP Single double quotation mark difference, PHP double quotation marks in PHP, the definition of the string can be used in English single quotation marks ", you can also use double quotation marks" ". But you must use the same single or ...

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