PHP 评论标签

标签 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 注释等效的内容?

最佳答案

这不会注释掉一个 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/

相关文章:

javascript - WooCommerce 单一产品页面上的倒计时器,直到产品销售结束

php - 如何在 php 中制作自动语音调用应用程序?

json - 如何检查任何必需的标签是否为空 Azure Policy

javascript - 从 html 代码获取平均评论数 - 从 div 数字中提取数字?

javascript - 在网页中嵌入网络浏览器

jquery 针对单个生成的列表标签

Javascript - 如何替换不在 HTML 标签中的空格?

visual-studio - 在 Visual Studio 中从类生成接口(interface)时如何复制注释?

visual-studio-2010 - 将指向另一个文件 (Word) 的超链接插入到 Visual Studio 代码文件中

css - 如何在 Facebook 评论框插件上应用自定义 CSS