Home >Backend Development >PHP Tutorial >The relationship and difference between PHP single and double quotes
Today we will explain the difference directly through a few practical cases, please pay attention!
// Knowledge about double quotes
// This writing method is wrong because it will regard hello as a double quote character, and world as an unknown character
$str1 = "hello"world"".'
';
// Correct writing: The world with double quotes should be added with escape characters, so that there will be no boundary ambiguity
$str1 = "hello "world"".'
';
echo $str1;
$str2 = "hello nrt world".'
'; // nr: line feed and carriage return, double quotes are OK Parsing
echo $str2;
$str3 = "hello $str1".'
'; $str4 = "hello $str1"; // After adding an escape character to $, the system will treat $str1 as an ordinary string instead of a variable
echo $str4; // Knowledge about single quotes
$str1 = 'hello nrt world'.'
'; str1;
$str2 = 'hello $str1'; Explaining the mixed use of quotation marks, we got 3 conclusions:
1. Single quotation marks cannot be escaped too much, only \ ' can be escaped, while double quotation marks can be escaped \ " n r t
2. Single quotation marks The $ variable symbol cannot be parsed, but double quotes can
3. Since single quotes do not need to consider many situations, single quotes perform faster than double quotes!
I believe that through tonight’s analysis, You will no longer have any questions about single and double quotation marks in PHP! If you think it is good, feel free to give me a tip
!
The above has introduced the relationship and difference between single and double quotation marks in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.