• Advertisement
Sign in to follow this  

[web] how to remove comments in .php file

This topic is 3293 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all, recently i was working on an open source php project and i was wondering if there is an easy way to remove all the comments from .php files ? any idea will be greatly appreciated! y.

Share this post


Link to post
Share on other sites
Advertisement
Why would you want to do that?

Anyway, you could use a text editor that has Search-and-Replace with regular expressions.
Something like
//.+?$
would find single-line comments.

Share this post


Link to post
Share on other sites
I don't want to be an arse, but "recently i was working on an open source php project" and "an easy way to remove all the comments" sounds very much like "how can I remove the license and copyright information".

Another possibility would be that you want to make your own project open source, but strip off all comments to obfuscate the code a bit, which is nothing but hypocrisy.

But: Pardon if I am wrong and the underlying license is so that you don't have to keep copyright information, or may even change the license terms, then everything is okay (being ethical is another thing). Then you also want to remove comment lines starting with '#', C like comments '/*'...'*/', and html comments outside php, going like '', plus maybe html comments inside strings, etc..

Have a look at ToohrVyks post.

Still, may I ask for what this it?

Share this post


Link to post
Share on other sites
i have one and i must say very important reason to remove the comments, and that's my boss asked me to do it. and i can assure you that there no copyright violations.

and more concrete on the topic, first thing i tried was using regular expressions but as /* */ comments are usually on some lines the text editor couldnt highlight them.

anyway thx for the ideas.

y.

Share this post


Link to post
Share on other sites
hmm,

i just now saw the whole documentation for php_strip_whitespace! it sounds promising. thx

y.

Share this post


Link to post
Share on other sites
Quote:
Original post by DpakoH
i have one and i must say very important reason to remove the comments, and that's my boss asked me to do it. and i can assure you that there no copyright violations.
And what's your boss's reason? I'd make sure there was a really good reason to remove comments first; you're making it difficult to maintain for yourself as well as anyone else.

Share this post


Link to post
Share on other sites
Quote:
Original post by DpakoH
i have one and i must say very important reason to remove the comments, and that's my boss asked me to do it. and i can assure you that there no copyright violations.


I cannot help, but for what else should that be good? It just increases unmaintainability. And I've never heard of performance boosts after removing comments.

Just giving you a hint: If it is really for the unlawful removal of license/copyright terms, you could be sued for cognisance, and if your boss is clever, you will be the only one sued. But then I don't know about your local laws.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement