开发者

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

开发者 https://www.devze.com 2023-03-25 18:07 出处:网络
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 <<<EO

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>
        </t开发者_开发百科r>
EOD;


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消