需要将代码注释放在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..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
我尝试过的注释分界的排列:
// <--  
// -->
和....
<-- //
--> //
两种情况均失败,让我在“ 0”内发表评论。 那么,如何在我的0英镑内注释我的代码呢?     
已邀请:
那是设计使然。一旦您成为Heredoc的一切,只要键入,直到结束为止,它都被视为一个长字符串的一部分。最好的选择是打破HEREDOC,发表评论,然后开始新的回显行
echo <<<_HEREDOC_FOO
    text text text
<<<_HEREDOC_FOO;
//Comments
echo <<<_HEREDOC_FOO
    text text text
<<<_HEREDOC_FOO;
正如其他人提到的那样,您可以进行HTML注释,但是那些查看您的源代码的人仍然可以看到它们     
您可以将注释字符串作为变量函数的参数传递。
function heredocComment($comment)
{
    return \"\";
}

$GLOBALS[\"heredocComment\"] = \"heredocComment\";

echo <<<_HEREDOC_FOO

   {$heredocComment(\"
   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;
    
尝试这个:
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;
现在是HTML注释     
实际执行此操作的最简单方法是使用与SeppoTaalasmaa相同的策略,但要短一些:
$comment = function($str) {return \'\';};
echo <<<_HEREDOC_FOO

       {$comment(\'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;
只需添加定义
$comment
的第一行,您就可以通过这种方式在下一个heredoc中插入注释。如果您不在全局范围内定义函数,这也将起作用。     

要回复问题请先登录注册