Heredoc technology. HTML and JavaScript scripts that can be used to output large segments
The function of the 1.PHP delimiter is to follow the original, including the newline format, and output something inside it;
2. Any special characters in the PHP delimiter do not need to be escaped;
The PHP variable in the 3.PHP delimiter is replaced with its value as normal.
As follows:
<? php $name = ' Shallow Water Tour ' ; // below <<<eot cannot have spaces after print <<<eot Hello , { $nam E }! Hello , $name ! </body> EOT; // Note that the Terminator at the end must be pulled over, preceded by a space ?
<? PHP $out = <<<EOF <a href= "Javascript:edit (' ASD ', ' aaa ') ' > Edit </a> | <font color= "#ccc" > Delete </font> <a href= "Javascript:confirmurl ('? m=admin&posid=12 ')" > Delete </a> | <font color= "Red" > Enable </font></a> | <a href= "Javascript:preview (' 3 ', ' ds ')" ><font color= "Green" > Demo </font></a>EOF; Echo $out ;? >
Attention:
1. Start with the <<<end start tag, end With end tag, * * The end tag must be written **, no indents and spaces, and a semicolon at the end of the tag. 2. The start tag is the same as the start tag, such as the usual uppercase EoT, EOD, EOF, but not limited to the few, as long as the start and end tags 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, $v =2 $a = <<<eof "abc" $v " 123 "eof; echo $a ; // result with double quotes output: "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. The first function outputhtml () { echo "; Echo "; Echo "<body> Home content </body>"; Echo "
PHP delimiter <<<eof Explanation