开发者

How do HTML comments work with PHP code?

开发者 https://www.devze.com 2022-12-18 01:33 出处:网络
I just wonder how does html comment tagwork with php code. If I have the following code, does php parse it anyway?

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 questi开发者_如何学运维on, but I guess it is important to know.


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.


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

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


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!<!---->
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号