What is the use of <<<EOD in PHP?

PhpSyntax

Php Problem Overview


I am implementing node to PDF using Drupal and tcpdf. In such case I am suppose to use this <<<EOD tag. If I don't use it, it throws error. I can't exactly get the purpose of <<<EOD.

Could anybody please explain the concept of this?

$html = <<<EOD
        <tr>
          <td>TEST</td>
        </tr>
EOD;

Php Solutions


Solution 1 - Php

That is not HTML, but PHP. It is called the HEREDOC string method, and is an alternative to using quotes for writing multiline strings.

The HTML in your example will be:

    <tr>
      <td>TEST</td>
    </tr>

Read the PHP documentation that explains it.

Solution 2 - Php

there are four types of strings available in php. They are single quotes ('), double quotes (") and Nowdoc (<<<'EOD') and heredoc(<<<EOD) strings

you can use both single quotes and double quotes inside heredoc string. Variables will be expanded just as double quotes.

nowdoc strings will not expand variables just like single quotes.

ref: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFeroView Question on Stackoverflow
Solution 1 - PhpPelleView Answer on Stackoverflow
Solution 2 - PhpPoomalairajView Answer on Stackoverflow