Difference between single quotes and double quotes _ php Tutorial

Source: Internet
Author: User
Php entry single quotes and double quotes are different. [1] single quotation marks and double quotation marks when processing variables: variables enclosed in double quotation marks will explain the values, but those enclosed in single quotation marks will not be processed and will be output directly ;? Php $ varmy [1] single quotation marks and double quotation marks are used to process variables:

Variables enclosed in double quotation marks are interpreted as values, but values enclosed in single quotation marks are not processed and directly output;

 

[2] to escape an operation in a statement, you must use double quotation marks.

For example, to define a single quotation mark, write it as follows:

$a = ‘He\’s name is Huige.’ ; 

The program will display the He \'s name is Tom. intact, if written as follows:

    $a = “He\’s name is Huige.”; 

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

========================================================== ================

The following lists the meanings of escape characters (they have special meanings when they are used in double quotation marks)

========================================================== ================

The following example demonstrates the difference between single quotes and double quotes:

 Quotation marks
 What you sell$ QuantityProduct, the unit price is\ $ Price. Plus the invoice tax, the total amount is\ $ Total.

\ N "; // print the result using single quotation marks: echo 'using single quotation marks:'; echo'

What you sell$ QuantityProduct, the unit price is\ $ Price. Plus the invoice tax, the total amount is\ $ Total.

\ N';?>

The final result is as follows:

========================================================== ======================================

========================================================== ======================================

1. in this example, double quotation marks are used to print the results. this is another solution for the single quotation marks printing result in this article (number of php entry variables.

2. in this example, because double quotation marks can print variables, we put all the items to be printed into double quotation marks, but the only problem is that the $ symbol is printed, to print the $ symbol, escape it directly.

3. What is the difference between using line breaks (\ n) in both quotation marks ???

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

========================================================== ======================================

FAQ:

1. there are also differences between single quotation marks and double quotation marks in terms of operation efficiency. Generally, the speed of single quotation marks is faster and double quotation marks are slower. The reason is that double quotation marks must first look for variables in the statement, you do not need to use single quotes. Therefore, use single quotes if the variables are not entered in the statement. This is a habit of writing programs, always thinking about improving program efficiency.

2. when HTML is printed using PHP, it is easiest to use single quotes.

Echo'

To print this HTML code using double quotation marks, you have to escape all double quotation marks in the string.

echo "
';

3. if you still do not know the difference between the two quotation marks, you can use double quotation marks, which is unlikely to cause problems.

Variables enclosed in double quotation marks will explain the value, but they are not processed in single quotation marks and are directly output ;? Php $ var = 'My...

";

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.