Adam
Adam

Reputation: 93

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 -->
<?php...

Thanks in advance.

Upvotes: 0

Views: 144

Answers (3)

rmflow
rmflow

Reputation: 4775

Just swap lines above and use php comment:

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

Upvotes: 0

Christian
Christian

Reputation: 28144

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...

Upvotes: 0

JohnP
JohnP

Reputation: 50039

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

Upvotes: 7

Related Questions