PHP HereDoc, NowDoc, and HereDoc VS NowDoc

Last updated May 15, 2020

PHP HereDoc

PHP heredoc is another way to create strings with a large amount of text without using quotations.

Syntax of PHP heredoc

To create strings with PHP heredoc way you have to use <<< operator. After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation.

<?php
$x = <<<EOD
your text goes here
EOD;
echo $x;
?>

Browser Output

your text goes here

In this above example, EOD is an identifier. You can give any name to an identifier. See the following example –