header image
 

Removing PHP comments

There’s a lot of talk on the internet about how difficult it is to remove comments from PHP e.g. if you want to pass a comment-free file onto a client.

There are boring time-consuming PHP scripts to do the business for you, there’s  php_strip_whitespace, there’s regex, there’s tokenizer, there are obfuscators, there are endless people saying that you shouldn’t put things you don’t want read into the comments, there are others who say that removing comments is impossible, and all in all it’s a nightmare of copy-and-paste ‘me-too’ answers, none of which work well.

Yeugh.

Google, in its infinite wisdom (sarcasm) promotes all these non-answers to the top of the SERPS because these non-answers are fresh and they’re on authority domains.

Nothing new there, then.

But – if you’re prepared to dig a little bit (no, dig a lot ‘cos the SERPS at the moment are rubbish) there is an answer.

It’s called ‘Extract or Remove Text Between Any Two Fields’ and you can buy this PHP comment removing software from Sobolsoft.

I have no affiliation with it.

I would suggest that if you want to remove single line comments at a later date you should put double slashes at the end of each comment \\, and that if there are multiple line comments that you want removed you enclose them thusly \**** some stuff ****\, leaving multi-line comments that you want to keep enclosed in the normal comment tags  \* more stuff *\

Couldn’t be simpler.

 

You can leave comments by clicking here, leave a trackback at http://www.alchemweb.co.uk/removing-php-comments/trackback/ or subscribe to the RSS Comments Feed for this post.

Leave a Reply

Allowed XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>