PHP EOF (Heredoc) is a method of defining a string in command-line shells such as sh, csh, ksh, Bash, PowerShell, and zsh, and programming languages such as Perl, PHP, Python, and Ruby.
Usage Overview:
1. The semicolon must be followed, otherwise the compilation will not pass.
2. EOF can be substituted with any other character, just to ensure that the end identity is consistent with the start identity.
3. The end identity must be shelf alone (i.e. must start at the beginning of the line, and cannot be connected to any whitespace and characters).
4. Start identification can be without quotation marks or with single double quotation marks, without quotation marks and with double quotes effect, interpreted inline variables and escape symbols, with single quotation marks does not explain the embedded variables and escape symbols.
5. When the content requires embedded quotation marks (single or double quotation marks), do not need to add escape character, itself to single double quotes escaped, here quite with the use of Q and QQ.
Instance
<?phpecho <<<eof
Attention:
1. Start with the <<<eof start tag, end with the EOF end tag, the end tag must be written in the head, cannot have indents and spaces, and there should be a semicolon at the end of the tag.
2. The opening and closing tags are the same, such as EOT, EOD, EOF, which are commonly capitalized, but are not limited to those (which can also be used: JSON, HTML, etc.), 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:
Instance
<?php$name= "Runoob"; $a = <<<eof "abc" $name "123" eof;//end requires a separate row and no space echo $a; >
This article explains in detail the use of the PHP EOF (heredoc), more learning materials to focus on the PHP Chinese network can be viewed.