<?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