<<<EOD 在 PHP 中有什么用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6924193/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:38:08  来源:igfitidea点击:

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

phpsyntax

提问by Fero

I am implementing node to PDF using drupal and tcpdf. In such case i am suppose to use this <<<EODtag. If i didn't give this o/p is not perfect. I can't exactly get the purpose of <<<EOD.

我正在使用 drupal 和 tcpdf 实现节点到 PDF。在这种情况下,我想使用这个<<<EOD标签。如果我不给这个 o/p 是不完美的。我无法完全理解<<<EOD.

Could anybody please explain the concept of this?

有人可以解释一下这个概念吗?

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

Thanks in advance....

提前致谢....

回答by The Pellmeister

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

那不是 HTML,而是 PHP。它称为 HEREDOC 字符串方法,是使用引号编写多行字符串的替代方法。

The HTML in your example will be:

您示例中的 HTML 将是:

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

Read the PHP documentationthat explains it.

阅读解释它的PHP 文档

回答by pooamlairaj

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

php 中有四种类型的字符串。它们是单引号 (')、双引号 (") 和 Nowdoc(<<<'EOD')和 heredoc(<<<EOD)字符串

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

您可以在 heredoc 字符串中使用单引号和双引号。变量将像双引号一样扩展。

nowdoc strings will not expand variables just like single quotes.

nowdoc 字符串不会像单引号那样扩展变量。

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

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