: This article mainly introduces the relationship and difference between single and double quotation marks in PHP. For more information about PHP tutorials, see. Today, we will explain the differences through several practical small cases. let's take a closer look!
// Double quotation marks
// This syntax is incorrect because it regards hello as a double quotation mark character, while world will become an unknown character.
$ Str1 = "hello" world "".'
';
// Correct syntax: add the escape character \ to the world with double quotation marks so that no boundary ambiguity will occur.
$ Str1 = "hello \" world \"".'
';
Echo $ str1;
$ Str2 = "hello \ n \ r \ t world ".'
'; // \ N \ r: line feed carriage return. double quotation marks can be parsed.
Echo $ str2;
$ Str3 = "hello $ str1 ".'
'; // At this time, the system parses $ str1 into a variable and calls $ str1
Echo $ str3;
$ Str4 = "hello \ $ str1"; // after $ matches the escape character, the system regards $ str1 as a normal string instead of a variable.
Echo $ str4;
// Single quotes
$ Str1 = 'Hello \ n \ r \ t world '.'
'; // Single quotes cannot be parsed and identified \ n \ r \ t, which will be directly output as common characters
Echo $ str1;
$ Str2 = 'Hello $ str1'; // single quotes cannot parse and recognize the $ symbol. $ str1 is output as a common character directly.
Echo $ str2;
The double quotation marks are mixed and explained. the following three conclusions are obtained:
1. single quotes cannot be escaped too much. they can only be escaped \ ', while double quotes can be escaped \ "\ n \ r \ t
2. $ variable characters cannot be parsed in single quotes, while double quotation marks can
3. because single quotes do not need to be considered in many cases, single quotes are faster than double quotes!
I believe that through tonight's analysis, you will not have any questions about the single double quotation marks in PHP in the future! If you think it is good, you can
Thank you!
The above describes the relationship and difference between single and double quotation marks in PHP, including the content, and hope to help those who are interested in the PHP Tutorial.