About NOWDOC and HEREDOC
phpcn_u66401
phpcn_u66401 2017-11-27 15:37:46
0
1
1233
<?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>


The browser displays the output:
Single quotes and double quotes in HEREDOC will not be parsed, but reference variables and special characters will be parsed
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
}

I just learned PHP. When testing NOWDOC, I found that both the html tag and the php tag in NOWDOC were interpreted and executed? I just want to print it out, no points -.-!

phpcn_u66401
phpcn_u66401

reply all(1)
Peter_Zhu

heredoc is similar to double quote syntax, nowdoc is only supported by php5.3+, similar to single quote syntax, especially suitable for outputting a large amount of html,

The difference between the two string declaration methods , please take a look at this course: http://www.php.cn/code/20794.html

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template