PHP Introductory single quote and double quotation mark Difference _php Tutorial

Source: Internet
Author: User
"1" single and double quotation marks when dealing with variables:

Variables enclosed in double quotation marks will interpret the values, but they are not processed in single quotes and are output directly;


"2" If you want to escape in the statement, then you must use double quotation marks.

For example, when you go to define single quotes, write this:

The program will show He\ 's name is Tom intact, if this is written:


The program will show: He's name is Tom.


The meanings of write escape characters are listed below (they have special meanings when using these characters in double quotation marks)

< span=""> < span=""> < span=""> < span=""> < span=""> < span=""> < span=""> < span=""> < span=""> < span=""> < span=""> < span=""> < span=""> < span=""> < span=""> < span="">


Here's an example to illustrate the difference between using single and double quotes:

  Use double quotes: "; echo"

$quantity \$ $price \$ $total.

\ n "//print result using single quote: Echo '

Use single quotation marks:

'; Echo '

$quantity \$ $price \$ $total.

\ n ';? >

The final results are as follows:



1. This example prints the result in double quotation marks, and is another solution to the single-quote print result of an example in this article (the number of entry variables for PHP).

2, in this case, because the double quotation marks are able to print out the variable, so we put everything to print in double quotes, but the only problem is to print the $ symbol problem, to print out the $ symbol, we can directly escape.

3. What is the difference between using a newline character (\ n) in both quotes???

A: When a newline character (\ n) is placed in double quotation marks, it creates a new line in the HTML source code. When placed in single quotation marks, it will print out \ and n directly.



1, in the operational efficiency of single quotation marks and double quotation marks are also different, in general, single quotation marks run faster, double quotation marks will be slower, because the double quotation marks to find whether there are variables in the statement, and single quotation marks are not used, so if there is no substitute variable in the statement as far as possible single quotation marks. This is a habit of writing programs, always thinking about improving the efficiency of the program.

2. When using PHP to print HTML, it is easiest to use single quotes.

echo ' 

If you want to print out this HTML code in double quotation marks, you will have to escape all double quotes in the string.

echo "

3, if you still don't know the difference between these two quotes, you can use double quotation marks, which is unlikely to be a problem. true techarticle "1" single and double quotation marks when dealing with variables: variables enclosed in double quotation marks will interpret values, but are not processed in single quotes, direct output;? php$var = ' My ...

  • Related Article

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