需要将代码注释放入定界文档中
好吧,我似乎无法在 foo.php
文件的 heredoc
块内添加注释:
echo <<<_HEREDOC_FOO
// okay this comment was intended to explain the code below but it
// is showing up on the web page HTML sent to the browser
<form action="foo.php" method="post">
<input type="submit" value="DELETE RECORD" /></form>
_HEREDOC_FOO;
表单是否有效,当然(顺便说一句,上面的表单代码是 高度截断 为了我的问题)。
但是该死的评论(好吧,这个评论是..blah blah blah
) 也出现在浏览器中。它显示在 浏览器就像上面写的那样:
// okay this comment was intended to explain the code below but it
// is showing up on the web page HTML sent to the browser
我尝试过的评论分界的排列:
// <--
// -->
和...
<-- //
--> //
在这两种情况下都失败,无法允许我在 heredoc
内发表评论。
那么我到底怎样才能在我的 heredoc
中注释我的代码呢?
Well I can't seem to add comments inside a heredoc
block in my foo.php
file:
echo <<<_HEREDOC_FOO
// okay this comment was intended to explain the code below but it
// is showing up on the web page HTML sent to the browser
<form action="foo.php" method="post">
<input type="submit" value="DELETE RECORD" /></form>
_HEREDOC_FOO;
Does the form work, sure (btw the form code above is highly truncated for
the sake of my question here).
But the dang comment (okay this comment was..blah blah blah
)
appears in the browser too. It shows up in the
browser just as written above:
// okay this comment was intended to explain the code below but it
// is showing up on the web page HTML sent to the browser
Permutations on the commenting demarcation I've tried:
// <--
// -->
and....
<-- //
--> //
FAIL in both cases to allow me to comment inside heredoc
.
So how the heck can I comment up my code within my heredoc
s?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是设计使然。一旦你成为你的heredoc,你输入的所有内容直到你结束它都会被视为一个长字符串的一部分。你最好的选择是打破你的 HEREDOC,发表你的评论,然后开始一个新的回显行
正如其他人提到的,你可以做 HTML 评论,但那些查看你的源代码的人仍然可以看到
That's by design. Once you being your heredoc EVERYTHING you type until you end it is treated as being part of one long string. Your best bet would be to break your HEREDOC, put your comment, then start a new echo line
As someone else mentioned you could do HTML comments, but those will still be visible to anyone who views your source code
您可以将注释字符串作为变量函数的参数传递。
You could pass the comment string as a parameter of a variable function.
试试这个:
它现在是一个 HTML 评论
Try this:
it is now an HTML comment
实际执行此操作的最简单方法是使用与 SeppoTaalasmaa 使用的相同策略,但更短:
只需添加定义
$comment
的第一行,您就可以在下一个heredoc中插入注释方式。如果您不在全局范围内定义该函数,这也将起作用。The simplest way to actually do this is using the same tactic as SeppoTaalasmaa used, but then shorter:
Just add the first line defining
$comment
, and you'll be able to insert comments in the next heredoc this way. This will also work if you're not defining the function in the global scope.