PHP EOF(heredoc)
##Usage overview:
- 1. It must be followed by a semicolon, otherwise the compilation will not pass.
- 2.EOF can be replaced by any other character, as long as the end identifier is consistent with the start identifier.
- 3. The end mark must occupy a line by itself (that is, it must start from the beginning of the line, and cannot be connected with any blanks or characters before and after).
- 4. The start mark can be without quotation marks or with single and double quotation marks. Without quotation marks, the effect is the same as with double quotation marks. Embedded variables and escape symbols are interpreted. With single quotation marks, the effect is the same. Embedded variables and escape symbols are not interpreted.
- 5. When the content requires embedded quotation marks (single quotation marks or double quotation marks), there is no need to add escape characters. The single and double quotation marks will be escaped by itself. This is equivalent to q and Usage of qq.
<?php echo <<<EOF <h1>我的第一个标题</h1> <p>我的第一个段落。</p> EOF; // 结束需要独立一行且前后不能空格 ?>
Note:
1. Start with <<<EOF start tag and end with EOF end tag , the closing tag must be written at the beginning, there must be no indentation or spaces, and there must be a semicolon at the end of the closing tag.
2. The start tag and the end tag are the same, such as commonly used uppercase EOT, EOD, EOF, but not limited to those (can also use: JSON, HTML, etc.), as long as the start tag and end tag are ensured The markup does not need to appear in the text.
3. Variables located between the start tag and the end tag can be parsed normally, but functions cannot. In the heredoc, variables do not need to be spliced with connectors . or , as follows:
<?php $name="runoob"; $a= <<<EOF "abc"$name "123" EOF; // 结束需要独立一行且前后不能空格 echo $a; ?>