Trace Trace - 7 months ago 48
HTML Question

Comment out HTML and PHP together

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 is not being commented out....is there a way to do this

Answer

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.