Alegro
Alegro

Reputation: 7956

How to comment mixed html and php code at once?

In Notepad++ I want temporary turn of this block of code:

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 comment markup - doesn't work.
php comment markup - doesn't work.

I can't believe that I must comment separately html and php code - 3+3 times ?

Upvotes: 1

Views: 14122

Answers (3)

MJD
MJD

Reputation: 1193

You can comment out all of your code by surrounding the whole thing in a PHP block comment. It would look something like:

<?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 */ ?>

Of course, putting the block comments in a separate PHP tag is not necessary. A reduced version looks like:

<?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']; */ ?>

Upvotes: 7

Sumit Malik
Sumit Malik

Reputation: 354

You have to use both html markups and php comment chars in php block. 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']; ?> -->

Better comment each line out as:

<!-- 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']; ?> -->

Upvotes: 2

laurent
laurent

Reputation: 90776

Just wrap the code in HTML comments:

<!--
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']; ?>
-->

Upvotes: 3

Related Questions