Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minify PHP in Visual Studio 2015

Is there any way to minify (or remove comments) in PHP using Visual Studio 2015? I use PHP Tools and when i release php scripts to public server, i would like at least remove all comments from code. I know, is there way to remove comments with content menu, but i wish to have comments in my project and no comments (or minimal and unread code) in publish scripts (some like Bundler & Minifier tool, but for php). Thanks

like image 714
user1173536 Avatar asked Mar 26 '17 16:03

user1173536


People also ask

How do I minify PHP HTML output?

Minification can be done by removing unnecessary details and eliminating excessive whitespaces, newlines, comments, etc. However, minification reduces the readability of the code. Minification can reduce file size upto 70%. PHP is used to transfer files from development to production environment.


3 Answers

There is basically no point in minifying Php since there is no performance gain in doing so. Although if you insist, there are a few ways to remove comments/whitespaces from source. (and these are not limited to just VisualStudio) -

  1. Use Gulp.
  2. Use Command line options: php -w file.php => generates file without comments & whitespaces. Equivalent to php_strip_whitespace()
  3. Use Regular Expression in Find-Replace Function of your IDE. You can use the following inside Find FieldBox. (and keep Replace fieldbox empty)

    //.* or /.

  4. Use a Library/tool like Php-Minify

Hope that helps!

like image 65
Niket Pathak Avatar answered Sep 28 '22 17:09

Niket Pathak


Why aren't you going to use online tool to do it? There are many online tools you can use instead of VS 2015.

Here is one tool for you. http://beta.phpformatter.com/

Hope it helps you and check this answer as solved if it helps you.

Thanks!

like image 44
Adams Xiao Avatar answered Sep 28 '22 16:09

Adams Xiao


You can check Comment Remover tool to remove all the comments from a file with a single button click. It also remove #regions and preserve XML Doc comments.

like image 28
Web Developer Claire Avatar answered Sep 28 '22 15:09

Web Developer Claire