php – 需要将代码注释放在heredoc中

前端之家收集整理的这篇文章主要介绍了php – 需要将代码注释放在heredoc中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
好吧,我似乎无法在我的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;

该表单是否有效,确定(顺便说一下上面的表单代码是高度截断的
为了我的问题,这里).

但是当时的评论(好吧这个评论是……布拉等等)
也出现在浏览器中.它显示
浏览器如上所述:

// 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内发表评论.

那么我怎么能在我的heredocs中评论我的代码呢?

这是设计的.一旦你成为你的heredoc一切你输入直到你结束它被视为一个长字符串的一部分.你最好的选择是打破你的HEREDOC,发表你的评论,然后开始一个新的回声线
echo <<<_HEREDOC_FOO
    text text text
<<<_HEREDOC_FOO;
//Comments
echo <<<_HEREDOC_FOO
    text text text
<<<_HEREDOC_FOO;

正如其他人提到的那样,您可以进行HTML注释,但查看源代码的任何人都可以看到这些注释

原文链接:https://www.f2er.com/php/135926.html

猜你在找的PHP相关文章