Home  >  Article  >  Backend Development  >  Let’s talk about the difference between PHP single quotes and double quotes_PHP Tutorial

Let’s talk about the difference between PHP single quotes and double quotes_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:38:331049browse

In fact, in the previous bkJia video tutorial, I talked about the difference and efficiency issues between single quotes and double quotes, but many friends still don’t understand it very clearly. They always thought that single quotes and double quotes in PHP are interoperable. It wasn't until one day that I discovered that there were errors in single quotation marks and double quotation marks that I started to study and research. So today I’m going to talk about their differences. I hope you won’t be confused by this anymore.

” ” Fields enclosed in double quotes will be interpreted by the compiler and then output as HTML code.

‘ ‘ The words in the single quotes are not interpreted and are output directly.

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, the usage of double quotes and single quotes can be confusing to novices. Here, I will give an example to illustrate.

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

select * from abc_table where user_name=’abc’;

SQL statement can be written as:

SQLstr = “select * from abc_table where user _name= ‘abc’” ;

Assume that variables are used in the query conditions, 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:

SQLstr = “select * from abc_table where user_name = ‘ . $user_name . ” ‘ “;

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

Compare:

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 decomposed into the following 3 parts:
1: “select * from table where user_name = ‘ ” //Fixed SQL statement
2: $user //Variable
3:” ‘ ”
Use "." to connect the strings 1, 2, and 3

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486483.htmlTechArticleIn fact, in the previous PHP100 video tutorial, I talked about the difference and efficiency issues between single quotes and double quotes. But many friends still don’t understand it very clearly. They always think that single quotes and double quotes in PHP...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn