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
-
In PHP comments are used also for programing eg. for dependency injection, so you shouldn't remove them if you are not sure what they are doing. If you wan't to hide your code on production server you can compile your code - check this: http://stackoverflow.com/questions/1408417/can-you-compile-php-code – Mateusz Wojtuła Mar 31 '17 at 08:40
-
Why not use an IDE better suited to PHP such as NetBeans or PHPStorm? – GordonM Mar 31 '17 at 15:47
-
Because i prefer c# language and php is 'homework'. I like Web Essentials and other web components in Visual Studio, long time ago i used Eclipse or NuSphere, but now i use few years only VS for work. I like publish in VS, because i mark only scripts (like js, css), with minify code, which will be publicate = less work to do. – MarTic Apr 01 '17 at 04:58
4 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) -
- Use Gulp.
- Use Command line options:
php -w file.php
=> generates file without comments & whitespaces. Equivalent to php_strip_whitespace() - Use Regular Expression in Find-Replace Function of your IDE. You can use the following inside Find FieldBox. (and keep Replace fieldbox empty)
//.* or /.
- Use a Library/tool like Php-Minify
Hope that helps!

- 1
- 1

- 6,323
- 1
- 39
- 51
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!

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

- 11
- 3
-
Thanks, i know how remove comments in editor, but i wish to know, how remove comments (or minifying code) with publishing all php files at once - to output directory. – MarTic Apr 07 '17 at 07:49
I think there is no tool for visual studio to do this. But you may use external tools to do the job. It's a common task to do this in build system like jenkins. The build system e. g. is able to react on many version control events.
But I also think that you want to make php code unreadable (like compiling). There are only a few options to hide your php code to other people. You could use ionCube for encrypting php files. But then you have to make sure, that the ionCube extension is also installed on the public web server. Also, ionCube is currently not available for php 7.2, only up to 7.1. Another option is to compile php code using HipHop, a PHP to C++ compiler engine: https://de.wikipedia.org/wiki/HipHop

- 1,314
- 2
- 14
- 32