How to comment mixed html and php code at once?
13,748
Solution 1
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']; ?>
-->
Solution 2
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']; */ ?>
Solution 3
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']; ?> -->
Author by
Alegro
Updated on June 13, 2022Comments
-
Alegro almost 2 years
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 ?
-
MJD over 11 yearsBe careful with that. The PHP code will still execute even though nothing will be rendered by the browser. If you include any code that has side effects, those effects will still occur even if you don't see the results.
-
Alegro over 11 years@MJD, thanks a lot. I didn't knew that. How it is possible ? The code will execute itself, although being commented ?
-
MJD over 11 years@Alegro, PHP ignores the HTML arround it. So even though you commented you the HTML code, PHP is not aware of that. So it executes the PHP code you have, and outputs it. But if you view the page in a browser, the HTML comments hide everything. If you view the page source, you will see that the PHP code still happened. That's why I suggested using PHP's comments instead. This blocks the PHP code, and thus blocks PHP from spitting out the HTML to begin with.
-
Matt over 8 yearsThis way PHP will not be processed, in contrast to the favoured answer. Correct me if I'm wrong.
-
Matt over 8 yearsIn Notepadd++: press CTRL+K.