Correction status:Uncorrected
Teacher's comments:
php输出字符串,单引号,双引号区别:
<meta charset="utf-8"> <?php header("Content-type:text/html;charset=utf-8"); $msg="hello"; //双引号解释内部变量,{}变量定界 echo "{$msg} world"; echo "<hr>"; //输出" ",\转义, echo "\"hello world\""; echo "<br>"; echo '\'hello\''; echo "<br>"; echo '"hello"' ; echo '<hr>'; //特殊字符 echo '转义字符\\,\n,\t,\$'; // \n 用<br>替换 echo nl2br("明天下雨\n是的"); echo "<hr>"; //不解析变量 echo "{\$msg} world"; echo "<hr>"; //heredoc,内部变量和特殊字符自动转义;直接使用双引号 $heredoc= <<< HEREDOC {$msg} 我们热忱欢迎来自"全国"各地的\nPHP爱好者. HEREDOC; echo nl2br($heredoc); //nowdoc,不解析变量和特殊字符;直接使用单引号 $nowdoc= <<< 'NOWDOC' {$msg} 我们'热忱欢迎'来自"全国"各地的\nPHP爱好者. NOWDOC; echo "<hr>"; echo $nowdoc; ?>
点击 "运行实例" 按钮查看在线实例