Example of single quotes and double quotes in PHP

Source: Internet
Author: User
Welcome to the Linux community forum and interact with 2 million technical staff to enter 1.php? $ Str frozen fish; echo $ str's blog address is www.xker.com; note that this is a single quotation mark. 2.php? $ Str frozen fish; echo $ str's blog address is www.xker.com; note that this is a double quotation mark, $ str

Welcome to the Linux community forum and interact with 2 million technical staff> enter 1.php? $ Str = 'frozen fish '; echo' $ str's blog address is http://www.xker.com '; // note that this is a single quotation mark. 2.php? $ Str = 'frozen fish '; echo "$ str's blog address is http://www.xker.com"; // note that this is a double quotation mark, $ str

Welcome to the Linux community forum and interact with 2 million technicians>

1. php

Echo '$ str's blog address is http://www.xker.com'; // note that this is a single quotation mark.

.>

2. php

$ Str = 'frozen fish ';

Echo "$ str's blog address is a http://www.xker.com"; // note that this is a double quotation mark, $ str has a space

.>

3. php

$ Str = 'frozen fish ';

Echo $ str. 'The blog address is http://www.xker.com'; // there is no impact on the single-double cited, it is said that the single cited speed is fast

.>

You can see the result 1. php shows the content in single quotes, and does not replace $ str with "frozen fish", that is, display "$ str blog address is http://www.xker.com" and 2. php and 3. php has changed $ str to "frozen fish", that is, the display is "frozen fish blog address is http://www.xker.com ",

In this way, the difference is obvious. Single quotes also treat the variable names as strings. Double quotation marks will automatically search for and replace the variable names. Note that if the variable name is followed by a common character (excluding punctuation marks, such as commas ), you must add a space after the variable name. Without the program, you cannot determine where your variable name ends.

Comparing php and 3.php, we can find that the double quotation marks can save a lot of effort when adding strings. We recommend that you use single quotes when no variables are needed. It is said that the speed is fast and I don't feel it.

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.