开发者

Prevent Comments from Parsing

Is there a way to hide commenting in my php/html file?

I want to add markup that I don't want people to be able to view in source in their browsers.

Is this possible?

<!-- Prevent this comment from being viewed -->
<开发者_StackOverflow社区?php...

Thanks in advance.


If you add comments as PHP, people won't see it in their browser.

<div> 
   <!-- This HTML comment can be seen by people -->
   <?php //But this PHP comment can only be seen by me :) ?>
</div>

http://en.wikipedia.org/wiki/PHP


I see what you mean. You can do that with output buffering:

<?php
   // this is not
?><!-- this is sent to browser -->

And with output buffering.

<?php

   ob_start();

   ?><!-- this is NOT sent to browser --> <b>This isn't sent as well!</b> <?php

   ob_end_clean();
?>

However, if you want to remove comments only, you need to do some parsing:

<?php

   ob_start();

   ?><!-- this is NOT sent to browser --><?php

   $html=ob_get_clean();

   // TODO: Use a DOM parser to parse $html and remove comments from it.

?>

That does sound a bit over-engineered though...


Just swap lines above and use php comment:

<?php...
// Prevented this comment from being viewed
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜