Difference between single quotes and double quotes in PHP

Source: Internet
Author: User
In fact, I have mentioned the difference and efficiency between single quotes and double quotes in the previous PHP100 video tutorial, but it is still not clear to many friends, I always thought that single quotes and double quotes in PHP were interconnected. I did not study them until one day I found that single quotes and double quotes were incorrect. So today I will talk about their differences, I hope you do not "> <LINKhref =" http://www.php100.com

In fact, I have mentioned the difference and efficiency between single quotes and double quotes in the previous PHP100 video tutorial, but it is still not clear to many friends, I always thought that single quotes and double quotes in PHP were interconnected. I did not study them until one day I found that single quotes and double quotes were incorrect. So let's talk about their differences today. I hope you will not be confused.

The fields in double quotation marks are interpreted by the compiler and then output as HTML code.

''Is output directly without being interpreted in single quotes.

It can be seen from the literal meaning that single quotes are faster than double quotes.

For example:
$ Abc = 'My name is tome ';
Echo $ abc // The result is: my name is tom
Echo '$ ABC' // The result is: $ abc
Echo "$ abc" // The result is: my name is tom

Especially when using MYSQL statements, double quotation marks and single quotation marks are confusing for beginners. here, we will give an example to describe them.

Assume that constants are used in the query conditions, for example:

Select * from abc_table where user_name = 'abc ';

The SQL statement can be written as follows:

SQLstr = "select * from abc_table where user _ name = 'abc '";

Assume that the query conditions use variables, for example:

$ User_name = $ _ REQUEST ['User _ name']; // string variable

Or

$ User = array ("name" =>$ _ REQUEST ['User _ name', "age" =>$ _ REQUEST ['age']; // array variable

The SQL statement can be written as follows:

SQLstr = "select * from abc_table where user_name = '". $ user_name. "'";

SQLstr = "select * from abc_table where user_name = '". $ user ["name"]. "'";

Comparison:

SQLstr = "select * from abc_table where user_name = 'abc '";

SQLstr = "select * from abc_table where user_name = '". $ user _ name. "'";

SQLstr = "select * from abc_table where user_name = '". $ user ["name"]. "'";

SQLstr can be divided into the following three parts:
1: "select * from table where user_name = '" // fixed SQL statement
2: $ user // variable
3 :"'"
Use "." to connect 1, 2, 3 strings.
 

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.