单引号字符串
只能转义斜杠(\)和单引号(\’)
双引号字符串
可以转义常见的符号,并且自带模板字符串功能
<?php
$name = 'Chinese';
$sentence = "I'm $name"!;
echo $sentence;
//输出为:I'm Chinese!
?>
Heredoc
类似于双引号字符串,但可以跨越多行,并且引号不会被转义,可以用$变量名或{$变量名}插入字符串,由于匹配机制的问题,建议都加上{}避免出错
<?php
$name = "Leng Feng";
$chinese = 'Chinese';
$sentence = <<< EOT
My name is $name, I'm {$chinese}!
EOT;
echo $sentence;
//输出为:My name is Leng Feng,I'm Chinese!
?>
Nowdoc
类似于多行的单引号字符串,不进行解析,一般用于插入大段的静态文本。
<?php
$name = "Leng Feng";
$chinese = 'Chinese';
$sentence = <<< 'EOT'
My name is $name, I'm {$chinese}!
EOT;
echo $sentence;
//输出为:My name is $name, I'm {$chinese}!
?>