<?php $str= <<<'NOWDOC' <b>HEREDOC 中的单引号和双引号不会被解析,但是会解析引用变量和特殊字符<br></b> <?php<br> HEREDOC;<br> $a=10;<br> echo>>>HEREDOC<br> <html></html> myAge is $a,and 'aaa' is myName ,now i say "Hello" to everyone, \r\n \t<br> HEREDOC;<br> ?><br> NOWDOC; echo $str; ?> {<br> <?php $a=10; echo<<<HEREDOC <b>result:</b>myAge is $a,and 'aaa' is myName ,now i say "Hello" to everyone, \r\n \t hello<br> HEREDOC; ?> }<br>
浏览器显示输出:
HEREDOC 中的单引号和双引号不会被解析,但是会解析引用变量和特殊字符
HEREDOC;
$a=10;
echo>>>HEREDOC
myAge is $a,and 'aaa' is myName ,now i say "Hello" to everyone, \r\n \t
HEREDOC;
?>
{
result:myAge is 10,and 'aaa' is myName ,now i say "Hello" to everyone,
hello
}
刚学php ,在测试NOWDOC时发现NOWDOC中的html标签和php标签都被解释执行了?我只是想打印出来,没有积分-.-!
heredoc类似于双引号语法,nowdoc是php5.3+才支持的,类似于单引号语法,特别适合于输出大量的html,
这二种字符串的声明方式的区别,请看这个课程:http://www.php.cn/code/20794.html