PHP评论标签

时间:2015-06-10 15:01:09

标签: php tags comments

在Java / JSP的精彩世界中,您可以使用这种形式的评论:

<%-- anything in here is ignored and does not get sent to the client 
     it can span multiple lines and is useful for commenting out blocks
     of JSP, including tags and HTML:
     <c:if test="${some.condition}">
       <p>All this is inside the comment</p>
     </c:if>
     <!-- this HTML comment is itself commented out of the JSP so will not be sent to the client --!>
--%>
<!-- but this is just an HTML comment and WILL be sent to the client -->

在一个不太精彩的PHP世界中,我能找到的唯一的评论参考是:

/*
  multi-line comment
*/

和这些:

// single line comment

但是这些不会注释掉HTML和PHP标签:

/*
 <? do_something() ?>
*/

导致/ *和* /呈现给浏览器,并且仍然调用do_something()。

是否有与PHP上面显示的JSP注释相同的内容?

1 个答案:

答案 0 :(得分:7)

这不会注释掉一个块的原因:

/*
 <? do_something() ?>
*/

只是你不是在php中,而是在html中,/* */不是html中的有效评论结构。

如果你有

<?php
/*
some_php();
?>
and html
<?php
more_php();
*/
?>

它会工作得很好。注释块中的php将不会被执行,并且它不会被发送到浏览器。

虽然在SO代码荧光笔上效果不好......

当您打开评论部分时,请确保您使用的是php(<?php标记之后)。