How to use PHP <<eof EOF
<?php
$name
=
‘浅水游‘
;
print
<<<EOT
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=gb2312"
/>
<title>Untitled Document</title>
<body>
<!--12321-->
Hello,
$name
!
</body>
EOT;
?>
|
Attention:
1. Start with a <<<end start tag, end With end tag, end tag must be written in the head, no indentation and space, and a semicolon at the end of the closing tag .
2. The start tag is the same as the start tag, such as EOT, EOD, and EOF, but not limited to those, as long as the start tag and end tag are not present in the body .
3. Variables located between the opening and closing tags can be parsed normally, but the function is not . In Heredoc, a variable does not need a connector. Or, to splice, as follows:
$v =2; $a = <<<EOF "abc" $v "123" EOF; |
echo $a; The result is output together with double quotes: "ABC" 2 "123"
4.heredoc is often used when the output contains a large number of HTML syntax D documents. For example: function outputhtml () to output the HTML home page. There are two ways to do this. Obviously the second is simpler and easier to read.
First Kind
function outputhtml () { echo " ; &NBSP;&NBSP;&NBSP;&NBSP; echo " &NBSP;&NBSP;&NBSP;&NBSP; echo "<body> Home page content </body>" Code class= "PHP plain"; &NBSP;&NBSP;&NBSP;&NBSP; echo "</HTML>; } |
How to use PHP <<eof EOF