Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comment out HTML and PHP together

Tags:

html

php

I have this code,

    <tr>       <td><?php echo $entry_keyword; ?></td>       <td><input type="text" name="keyword" value="<?php echo $keyword; ?>" /></td>     </tr>     <tr>       <td><?php echo $entry_sort_order; ?></td>       <td><input name="sort_order" value="<?php echo $sort_order; ?>" size="1" /></td>     </tr> 

and I would love to comment both in one shot...but when I try

    <!-- <tr>       <td><?php echo $entry_keyword; ?></td>       <td><input type="text" name="keyword" value="<?php echo $keyword; ?>" /></td>     </tr>     <tr>       <td><?php echo $entry_sort_order; ?></td>       <td><input name="sort_order" value="<?php echo $sort_order; ?>" size="1" /></td>     </tr> --> 

the page fails - it seems the PHP code is not being commented out... Is there a way to do this?

like image 703
Matt Elhotiby Avatar asked Apr 25 '11 17:04

Matt Elhotiby


1 Answers

Instead of using HTML comments (which have no effect on PHP code -- which will still be executed), you should use PHP comments:

<?php /* <tr>       <td><?php echo $entry_keyword; ?></td>       <td><input type="text" name="keyword" value="<?php echo $keyword; ?>" /></td>     </tr>     <tr>       <td><?php echo $entry_sort_order; ?></td>       <td><input name="sort_order" value="<?php echo $sort_order; ?>" size="1" /></td>     </tr> */ ?> 


With that, the PHP code inside the HTML will not be executed; and nothing (not the HTML, not the PHP, not the result of its non-execution) will be displayed.


Just one note: you cannot nest C-style comments... which means the comment will end at the first */ encountered.

like image 101
Pascal MARTIN Avatar answered Oct 05 '22 13:10

Pascal MARTIN