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

我正在使用 Drupal 和 tcpdf 实现从节点到 PDF 的转换。在这种情况下,我应该使用这个 <<<EOD标记。如果我不使用它,它会抛出错误。我不太明白 <<<EOD的作用。

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

$html = <<<EOD
<tr>
<td>TEST</td>
</tr>
EOD;
133926 次浏览

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