Home > Article > Backend Development > Detailed explanation of the differences between the three PHP string delimiters
This article mainly shares with you the detailed explanation of the differences between the three PHP string delimiters. I hope it can help you.
The difference between single quotes, double quotes, <<< is as follows:
Previous: Today I suddenly encountered << 1. Single quotes: 'a string' 2. Double quotes: ”a $better string\n” 3. "Here-doc" syntax: PHP delimiter << Its functions can be summarized into three points: 1. The function of the PHP delimiter is to output everything inside it as it is, including line breaks and other formats; 2. Any special characters in the PHP delimiter do not need to be escaped and are written as usual; 3. The PHP variables in the PHP delimiter will be replaced with their values normally (php parse nested variables). Notes: 1. The character EOT after <<< is self-defined. Anything is acceptable, but the character at the end must be the same. , they appear in pairs. 2. Start with << 3. Embedded PHP variables should be enclosed in {} when necessary to tell the PHP parser that this is a PHP variable, such as {$name} to avoid ambiguity. {} is not needed in other cases. . Based on the above, it can be seen that the execution efficiency of single quotes is higher than the latter two. Therefore, it should be considered appropriately during use. Related recommendations: Mastering the basic knowledge of php - four kinds of delimiters The above is the detailed content of Detailed explanation of the differences between the three PHP string delimiters. For more information, please follow other related articles on the PHP Chinese website!
\' is the only escape code and cannot embed variables (the included variables are not parsed and are just output as they are).
Standard escape codes can be used normally, and variables can be embedded (the included variables will be parsed by PHP). 1 $a=1;
2 echo <<<EOT
3 <script language="JavaScript" type="text/JavaScript">
4 var a = $a;
5 alert(a);
6 </script>
7 EOT;
Note: