-3

How should I proceed with commenting out the following HTML code embedded with PHP?

<div class="check" data-product="<?php echo $product->id; ?>">PRICE AND 
AVAILABILITY</div>

Thanks.

slevy1
  • 3,797
  • 2
  • 27
  • 33
emiliano
  • 189
  • 2
  • 16

4 Answers4

3

You can comment all HTML or specifically the php code only.

To Comment in HTML way

 <!-- <div class="check" data-product="<?php echo $product->id; ?>">PRICE 
 AND AVAILABILITY</div>  -->

To Comment in PHP way

<div class="check" data-product="<?php // echo $product->id; ?>">PRICE AND 
   AVAILABILITY</div>

Or you can hide the entire portion using php in this way

<?php
/*
<div class="check" data-product="<?php echo $product->id; ?>">PRICE AND 
AVAILABILITY</div>
*/
?>
1

Use PHP-tags and comment it out:

<?php
    /*

    <div class="check" data-product="<?php echo $product->id; ?>">PRICE AND AVAILABILITY</div>

    */
?>
modsfabio
  • 1,097
  • 1
  • 13
  • 29
0

Using HTML: (Will still be visible in source code)

<!--<div class="check" data-product="<?php echo $product->id; ?>">PRICE AND 
AVAILABILITY</div>-->

Using PHP:

<?php 
/* 
<div class="check" data-product="<?php echo $product->id; ?>">PRICE AND 
AVAILABILITY</div>
*/
0

To comment out any HTML, whether or not it has PHP embedded in it, all one needs are the HTML comment marks "!--" and "--", as follows:

 <!--div class="check" data-product="<?php $id = "293";
echo $id; ?>">PRICE AND AVAILABILITY</div-->

If you browse a page containing this bit of HTML, you won't see that line. If you do a view-source of the page, you may note that the PHP code did get processed. In order to avoid the PHP code executing you could use the PHP comment marks of either "/* */" or "//", as follows:

<!--div class="check" data-product="<?php /*$id = "293";
echo $id;*/ ?>">PRICE AND AVAILABILITY</div-->


<!--div class="check" data-product="<?php //$id = "293";
echo $id; ?>">PRICE AND AVAILABILITY</div-->

Another way that uses the HTML "!" for preventing the PHP code to execute:

<!--div class="check" data-product="<!--?php /*$id = "293";
echo $id;*/ ?>">PRICE AND AVAILABILITY</div-->

The disadvantage of the HTML comment is that one has to remove it before finalizing the page, otherwise the user suffers the inconvenience of having to download extraneous data. The technique mentioned in two other examples of using PHP tags with comments avoids an imposition for the user and does not disclose what was commented out.

A related discussion shows a neat way to use PHP to comment out HTML or HTML embedded with PHP and allow for one to later easily undo commenting out the code, as follows:

<?php /* ?>
 <div class="check" data-product="<?php $id = "293";
    echo $id; ?>">PRICE AND AVAILABILITY</div>
<?php // */ ?>

Later one may expeditiously remove the comment by altering the opening PHP tag, as follows:

<?php //* ?>

See demo

slevy1
  • 3,797
  • 2
  • 27
  • 33