Easy Tutorial
❮ Php Imagealphablending Php Constant Arrays ❯

PHP EOF (heredoc) Usage Instructions

PHP EOF (heredoc) is a method 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

<?php
echo <<&lt;EOF
        <h1>My First Heading</h1>
        <p>My first paragraph.</p>
EOF;
// The end must be on a separate line with no preceding or following spaces
?>

Note:

  1. Start with the <<&lt;EOF start tag and end with the EOF end tag. The end tag must be written at the beginning of the line, without indentation or spaces, and a semicolon must be at the end of the end tag.

  2. The start and end tags must be the same, such as commonly used uppercase EOT, EOD, EOF, but not limited to those (also can use: JSON, HTML, etc.), as long as the start and end tags do not appear in the text.

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

Example

<?php
$name = "tutorialpro";
$a = <<&lt;EOF
        "abc"$name
        "123"
EOF;
// The end must be on a separate line with no preceding or following spaces
echo $a;
?>
❮ Php Imagealphablending Php Constant Arrays ❯