首先要了解下定界符
php可以使用
<?php
echo <<<EOT
this is body
this is body as well
EOT
;
這種方式來輸出大段文字,其中EOT就是定界符,定界符有分為開始定界符和結束定界符,定界符可以是任何內容,只要保證開始定界符和結束定界符一致就行,比如
<?php
echo <<<AAA
this is body
this is body as well
AAA
;
這就是heredoc的寫法,heredoc中的變量會被解析成具體的值
<?php
$a = 'this is string';
echo <<<AAA
this is body
this is body as well
$a
AAA
;
// output
this is body
this is body as well
this is string
如果希望內容不被解析,可以在開始定界符的兩邊加上單引號'EOT'
<?php
$a = 'this is string';
echo <<<'AAA'
this is body
this is body as well
$a
AAA
;
// output
this is body
this is body as well
$a
這就是nowdoc的寫法