1

在记事本++中,我想暂时关闭这段代码:

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 次?

4

3 回答 3

7

您可以通过将整个内容包含在 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']; */ ?>
于 2013-01-07T07:04:17.887 回答
3

只需将代码包装在 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']; ?>
-->
于 2013-01-07T07:02:03.193 回答
2

您必须在 php 块中同时使用 html 标记和 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']; ?> -->

最好将每一行注释为:

<!-- 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']; ?> -->
于 2013-01-07T07:04:34.327 回答