The difference between single quotes and double quotes in PHP. In programming languages, both single quotes and double quotes play an important role, as in PHP. Compared with ASP, PHP quotes are easier to use. in ASP, data should be replaced in programming languages, whether it is
Single quotesOr
Double quotation marksAnd has a very important role in
PHPThe same is true for languages. PHP quotes are easier to use than ASP quotes. in ASP, to substitute data into a variable, you must use double quotation marks. In addition, you can only use single quotation marks when using the quotation marks, double quotation marks are not allowed. if double quotation marks are used, they are treated as the ending character of the previous quotation marks.
But in PHP, there is no such restriction. Replace the value with a variable. single quotation marks and double quotation marks can be used, but must be used in pairs.
In PHP, if it is only used for text data that does not contain variables, there is no difference between single quotation marks and double quotation marks. However, to use variables, single quotes and double quotation marks are different.
In PHP, variables can be directly substituted into double quotes without definition or other symbols,
For example:
- $ B = "cat"; $ a = "This is a $ B"; // Display This is a cat
It cannot be enclosed in single quotes. if
- $ A = 'This is a $ B '; // This is a $ B.
There is also a difference between single quotes and double quotes in terms of operation efficiency. Generally, the speed of single quotes is faster, and double quotes are slower. The reason is that the 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.
If you want to convert the definition operation in the statement, you must use double quotation marks.
For example, to define a single quotation mark, write it as follows:
- $a = ‘He’s name is Tom.’ ;
The program will display the He's name is Tom. intact, if written as follows:
- $a = “He’s name is Tom.”;
The program will display: He's name is Tom.
Single quotation marks are a stumbling block to SQL statements. text data in SQL statements must be included in single quotation marks. Therefore, if single quotation marks appear in the data, the database considers the data to end, the subsequent data will be considered as other components of the SQL statement, and of course an error will be reported during database query. Therefore, the text data written into the SQL statement must use addslashes () the function is converted to single quotes, and stripslashes () is used for data reading.
Single quotation marks and double quotation marks (") of" comment "play an important role. They are also used in PHP. Compared with ASP, PHP quotes are easier to use. in ASP, data should be replaced...