EOT 和 HTML 有什么区别?在 PHP 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15182691/
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-25 08:43:48  来源:igfitidea点击:

What is the difference between EOT and HTML? in PHP

php

提问by Wesley Brian Lachenal

I've seen some people using this code.

我见过一些人使用此代码。

echo <<< EOT
Hi <br>
EOT;

and

echo <<< HTML
Hello<br>
HTML;

What's the difference of those two? and why would not they use the normal echo? like

这两者有什么区别?为什么他们不使用正常的回声?喜欢

echo "How are you<br>"?

回答by AlienWebguy

Nothing, it's just a delimiter for the HEREDOCsyntax. The only benefit of using HEREDOC is you can keep indents and structure of your string in the source code. It tends to be nicer to work with than concatenated strings - for your example Hi <br>, there is no good reason to use HEREDOC.

没什么,它只是HEREDOC语法的分隔符。使用 HEREDOC 的唯一好处是您可以在源代码中保留字符串的缩进和结构。它往往比串联字符串更好用 - 对于您的示例Hi <br>,没有充分的理由使用 HEREDOC。

回答by Your Common Sense

why would not they use the normal echo?

他们为什么不使用正常的回声?

Using heredoc for this very example makes no sense.
And it's indeed to use echoto print out single text line.
So, nobody is using heredoc for this.

在这个例子中使用 heredoc 是没有意义的。
它确实用于echo打印出单个文本行。
因此,没有人为此使用heredoc。

Also, in echoing large text blocks heredoc is useless again, as one have to just close PHP tag and write the text as is.

此外,在回显大文本块时,heredoc 再次无用,因为您必须关闭 PHP 标签并按原样编写文本。

The onlyuse of heredoc is when you need to store a large block of text in a variable.

Heredoc的唯一用途是当您需要在变量中存储大块文本时。

$var = <<< HERE
Hello %s!
Please follow this link %s to continue registration.
HERE;

回答by Brian Pinto

May be very very very late to comment but, in context of today's IDEs: When you use HEREDOCS the identifiers provide a hint as to what kind of information is being stored

评论可能会非常非常晚,但是,在今天的 IDE 环境中:当您使用 HEREDOCS 时,标识符会提供有关正在存储的信息类型的提示

Say <<<SQLthe IDE's syntax highlighter may use the SQLidentifier for highlighting the contents of the string as an SQL Query. <<<HTMLfor HTML highlighting ... and so forth.

假设<<<SQLIDE 的语法高亮器可以使用SQL标识符将字符串的内容高亮显示为 SQL 查询。<<<HTML用于 HTML 突出显示......等等。