views:

179

answers:

4

Hi,

I just wonder how does html comment tag work with php code.

If I have the following code, does php parse it anyway?

<!--
<?php
   echo "hi";
?>
-->

a simple question, but I guess it is important to know.

+16  A: 

Oh yes, anything in PHP blocks gets executed, but in this case, it isn't shown to the end user because it's in HTML comments.

In the source of the page that is generated by this PHP script, you will see the output surrounded by HTML comments, simple as that.

The only way comments will affect the output of a PHP script is with valid PHP comments.

Jacob Relkin
Now, I am confirmed. Thank you a lot!
Moon
+3  A: 

Yes it does. If that is between <?php ?> tags

You can use PHP comments /* commment */ and they won't execute.

Pentium10
Thank you a lot!
Moon
+3  A: 

As a side note to the answers above: You can also interrupt the HTML comment:

<!--
  <?php
    echo "-->This will be seen!<!--";
  ?>
-->

gives this output:

<!--
  -->This will be seen!<!---->
Boldewyn
A: 

Is it really that hard to test it out for yourself?

symcbean
@symcbean// Yes, it is. Why would I ask here if I knew how to test it?
Moon
-1 Should be a comment
waiwai933