开发者

How to decomment an html/php webpage?

A crazy question:

Imagine a webpage file called somepage.php And it contains some html php contents in my editor I see:

<html><head></head><body>  
<?=$we开发者_开发知识库lcome . $essay . $thatsAllForNowFolks . $footer ?>

<!--
Blue
Ball
Bell
Blow
Bows
Bats
Beef
Bark
Bill
Boss

-->
</body></html>

When I browse my site I see those comments in the final result, while I only want that comment to be only in my editor for my secretive inspirations and don't want the whole world to know what I'm thinking when I'm developing, as well as I see those comments for any and all my website visitors as wasted bandwitch of internet speed.

How do I decomment my entire html/php files at the moment the html is served? Ideas, code and suggestions are much appreciated. My thanks in advance...


Probably the easiest solution is to write your comments in PHP. This way they will not be sent to the client in the source code. You can do it like this:

<html>

<?php
    //A single comment

    /*
         Some more
         comments
    */
?>

</html>


Basically the same as Michiel's approach but I'm lazy so I would use the abbreviated tags, just be sure you have short_open_tag set to 1 in your php.ini config.

<html><head></head><body>  
<?=$welcome . $essay . $thatsAllForNowFolks . $footer ?>

<? /*
Blue
Ball
Bell
Blow
Bows
Bats
Beef
Bark
Bill
Boss

*/ ?>
</body></html>


It depends on the complexity of your pages/comments.

You could strip them out using strpos and str_replace, or maybe a regular expressions. But HTML isn't a regular language, so the best way would be using a DOM parser, stripping out the comments.

(You could register your function as a output filter in php, using the output buffering functions like ob_start)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜