在PHP中,有什么作用。代表?
例如:
$sql = <<<MySQL_QUERY
For example:
$sql = <<<MySQL_QUERY
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
例如:
$sql = <<<MySQL_QUERY
For example:
$sql = <<<MySQL_QUERY
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
那是Heredoc语法。您可以通过将
&lt;&lt;&lt;&lt;&lt;
加上您选择的代币启动Heredoc字符串,并仅将令牌(和其他任何内容)放在新行上来终止它。为了方便起见,有一个例外:允许您在结束定界符之后添加一个分号。例子:
That's heredoc syntax. You start a heredoc string by putting
<<<
plus a token of your choice, and terminate it by putting only the token (and nothing else!) on a new line. As a convenience, there is one exception: you are allowed to add a single semicolon after the end delimiter.Example:
这称为a heredoc ,它可以让您进行一段长的文本,这些文本会遍布几行。您可以将PHP变量放入其中,它们将替换为值。一词图可以是任何东西。仅需开始并停止引用文本开始的地方,就只需要相同。
您可以通过附加多个引用的字符串来完成相同的操作,但这在大多数时候对于此HTML文本(例如HTML文本)来说更为清洁。还有一种叫做a nowdoc ,就像是单个引用字符串PHP,但这些不会让您在其中使用变量。
This is called a heredoc, and it lets you do a long piece of text that goes over several lines. You can put PHP variables in there and they will replace with the value. The word CHART can be anything. It just needs to be the same to start and stop where the quoted text begins.
You could do the same thing by appending multiple quoted strings, but this is cleaner most of the time for extended documents like this HTML text. There is also something called a nowdoc which is like a single quote string in PHP, but these won't let you use variables inside them.
它是使用 Heredoc语法。
It is the start of a string that uses the HEREDOC syntax.
是php的 。
例子:
It's PHP's
heredoc
.Example:
这是Heredoc,对于长字符串,您不必担心引用标记等。如果您注意到图表一词,然后有一行说图表;这表示字符串的末尾。
使用这种格式时要记住的重要事情是,无论您用来定义字符串末端的字符串(例如在这种情况下)角色可以在同一条线上的半分钟之后发生,甚至是空格,否则PHP认为这是字符串的一部分。
It's a heredoc, for long strings that you don't have to worry about quotation marks and whatnot. If you notice the word CHART and then there's a line that says CHART;, that indicates the end of the string.
The important thing to remember when using this format is that whatever string you use to define the end of the string (such as CHART in this case), that word has to appear on a line on its own, followed by a semicolon, and NO characters can occur after the semicolon on the same line, even whitespace, otherwise PHP thinks it's part of the string.
这是。
It's the heredoc syntax.
我发现
Heredoc
和nowdoc
在php
中实用了极限且有用,我很惊讶,到目前为止,没有人给您提供更多的示例做。首先,
heredoc
和nowdoc
很简单,heredoc
:就像“双引号”字符串,您可以放置变量nowdoc
:就像''单Quote string 没有变量被解析在以下示例中,我只会显示
heredoc
,要制作nowdoc
只需将令牌包装在单引号中 - &gt; 'token'。功能和优势
。
简单示例
输出
配方
&lt; br&gt;
每行这起作用,因为Heredoc将每个\ n解释为实际行
创建小组件
或仅放入一个字符串,然后使用1个回声
文档
I found both
Heredoc
andNowdoc
extremelly powerfull and usefull inPHP
and I am surprise that no one have so far give more example of what you can do.First the difference between
Heredoc
andNowdoc
is simple,Heredoc
: Is like the "" double quote string you can put VariablesNowdoc
: Is like the '' single quote string no variable are parsedFor the following example I will only show the
Heredoc
, in order to make aNowdoc
just wrap the token inside single quotes -> 'TOKEN'.Features and Advantages
with nl2br .
Simple Example
output
Recipes
<br>
for each lineThis works because HEREDOC interpretes each \n as an actual line
Create small components
Or just put in one string then output with 1 echo
Documentation
要了解一个明确的想法:
如果我们使用
&lt;&lt;&lt;
:结论:如果我们使用第一个方法,则必须将其转换为
json_encode()
以某种方式将其转换为需要一些处理。相反,我们可以使用&lt;&lt;&lt;
操作员节省一些时间并获得一些干净的代码。 :)To get a clear idea:
If we use
<<<
:Conclusion: If we go with the 1st method we have to convert it into
json_encode()
which somehow requires some processing. Instead, We can use the<<<
operator to save some time and get some clean code. :)