Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP EOF (heredoc) Usage

PHP EOF (heredoc) Usage

PHP EOF (heredoc) is a way to define a string in command-line shells (such as sh, csh, ksh, bash, PowerShell, and zsh) and programming languages (like Perl, PHP, Python, and Ruby).

Usage overview:

Example

My first heading        

My first paragraph.

EOF ; // the end must be on its own line with no spaces before or after ?>

Note:

1. Start with <<

2. The opening and closing markers are the same, e.g. the commonly used uppercase EOT, EOD, EOF to represent them, but not limited to those (you can also use: JSON, HTML, etc.), as long as the opening and closing markers do not appear in the body text.

3. Variables between the opening and closing markers can be parsed normally, but functions cannot. In heredoc, variables do not need to be concatenated with the . or , operator, as shown below:

Example