如何一次评论混合的html和php代码?

时间:2013-01-07 07:00:09

标签: comments notepad++

在Notepad ++中,我希望暂时关闭这段代码:

Number of registered users: <?php echo $objUsers->users['total']; ?><br/>
Newest user: <?php echo $objUsers->users['last']; ?>
<h5>Online users:</h5> <?php echo $objUsers->users['online']; ?>

html评论标记 - 不起作用。
php评论标记 - 不起作用。

我无法相信我必须单独评论html和php代码 - 3 + 3次?

3 个答案:

答案 0 :(得分:4)

您可以通过围绕PHP块注释中的所有内容来注释掉所有代码。它看起来像是:

<?php /* ?>
Number of registered users: <?php echo $objUsers->users['total']; ?><br/>
Newest user: <?php echo $objUsers->users['last']; ?>
<h5>Online users:</h5> <?php echo $objUsers->users['online']; ?>
<?php */ ?>

当然,不必将块注释放在单独的PHP标记中。简化版本如下:

<?php /* ?>
Number of registered users: <?php echo $objUsers->users['total']; ?><br/>
Newest user: <?php echo $objUsers->users['last']; ?>
<h5>Online users:</h5> <?php echo $objUsers->users['online']; */ ?>

答案 1 :(得分:2)

将代码包装在HTML注释中:

<!--
Number of registered users: <?php echo $objUsers->users['total']; ?><br/>
Newest user: <?php echo $objUsers->users['last']; ?>
<h5>Online users:</h5> <?php echo $objUsers->users['online']; ?>
-->

答案 2 :(得分:2)

你必须在php块中同时使用html标记和php注释字符。 E.g。

<!-- Number of registered users: <?php //echo $objUsers->users['total']; ?><br/>
Newest user: <?php // echo $objUsers->users['last']; ?>
<h5>Online users:</h5> //<?php echo $objUsers->users['online']; ?> -->

最好将每一行评论为:

<!-- Number of registered users: <?php //echo $objUsers->users['total']; ?><br/> -->
<!-- Newest user: <?php // echo $objUsers->users['last']; ?> -->
<!-- <h5>Online users:</h5> //<?php echo $objUsers->users['online']; ?> -->