在精彩的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 注释等效的内容?
最佳答案
这不会注释掉一个 block 的原因:
/*
<? do_something() ?>
*/
只是你不是在 php 而是在 html 和 /* */
在 html 中不是有效的评论结构。
如果你有
<?php
/*
some_php();
?>
and html
<?php
more_php();
*/
?>
它会工作得很好。注释 block 中的 php 将不会执行,并且不会将任何内容发送到浏览器。
虽然它在 SO 代码高亮器上效果不是很好......
当您打开评论部分时,请确保您在 php 中(在 <?php
标记之后)。
关于PHP 评论标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30760162/