Minify PHP in Visual Studio 2015 - php

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

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!

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!

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.

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

Related

how to check php function source code using eclipse

I'm curious on how certain php functions are implemented internally. e.g. array_values().
So in eclipse, I control click on the function name, which took me to a page that contain function prototype definition, but contains no internal source code.
Is there any way to see the internal implementation of php function using eclipse? (whether the function is written in php or c)
If it is not possible to see the php source code using eclipse, then does anyone have any good strategies at searching through the php source code on github?
Is there any way to see the internal implementation of php function using eclipse?
Unfortunately, no.
what is the best search strategy to search through the php source code, especially for a beginner like me, who feels very much lost in the vast amount of php source code
I'm assuming what you are really after here is a reference for native PHP functions and their input parameters and out types. In which case the official documentation is probably the best way to go about it.
Some (most?) popular IDEs such as Eclipse and Phpstorm can also give you an auto-generated phpdoc block for PHP's built-in functions that will give that information directly in your IDE.
If you are interested in the actual C implementation of most php functions, you can either navigate through the GitHub repository directly or clone it on your computer and open it in an IDE (Eclipse, CLion, etc...) and use the IDE navigation.
You can download the PHP source code from GitHub (https://github.com/php/php-src)
but the core of PHP is written in C language.
Use notepad++ to search the required details from the downloaded source code.
For example code for PHP array will be in this file :
https://github.com/php/php-src/blob/master/ext/standard/array.c
Notepad++ is the good editor with a lot of additional functionality like search string through files. (Find in files)
Hope it helps
Thanks
As an alternative, consider running OpenGrok in a Docker container. OpenGrok is an open-source and free source code indexer with advanced search mechanisms. (I am not affiliated with the project in any way)
Setting it up is easy (assuming you have Docker already installed):
# Make a directory that will contain source files for opengrok to index
mkdir ~/opengrok
# Clone the PHP source into that directory
git clone https://github.com/php/php-src.git ~/opengrok/php-src
# Start the OpenGrok container
docker run -d -v ~/opengrok:/src -p8081:8080 opengrok/docker
Now you should wait a minute or two for OpenGrok to fully index the source tree.
Open your browser
We want to search for the array_values implementation
Select the implementation in array.c
There you have it! The C implementation of array_values.

what to use for php documentation generation?

What do you use for automatic PHP docs generation.
I know about phpdocumentor. but it looks like it didn't have a single release within 2010.
Should I just use it or are there any alternatives?
You can try using DocBlox, a Documentation Generation application inspired on phpDocumentor.
Please see http://www.docblox-project.org for the website and/or http://demo.docblox-project.org/default for a demo.
We use Doxygen at work, but I must confess that I haven't used them much since setting it up in our continuous integration server. NetBeans and other IDEs parse and display the docs when you hover over and auto-complete items.
PHPdocumentor 2 is currently in alpha phase but still usable, so it seams that the project development ist continued.

PHP syntax highlighting in Visual Web Developer?

I recently installed PHP 5 on IIS, however, I am unable to find a PHP syntax highlighting plug-in or extension for VWD. Where can I find a plug-in? I thought there was an official one.
Consider PHP IDE for Visual Studio.
http://www.jcxsoftware.com/vs.php
I have used this and it adds a lot of nice PHP specific features to Visual Studio.
From their site...
Editor and File Management
•PHP4 and PHP5 Support
•Syntax Coloring for PHP, Smarty, HTML, JavaScript, CSS, XML and XSLT
•File templates for PHP, Smarty, HTML, JavaScript, CSS, XML and XSLT
•Intellisense for PHP, Smarty, HTML, JavaScript, CSS, XML and XSLT
Debugging
•XDebug and DBG support
•Debug PHP, JavaScript and .Net in one single session
•Built-in Apache web server for ease of debugging. Preconfigured with Php4, Php5, XDebug and DBG.
I've tried a lot of text editors, some free, some commercial. So far Visual Studio is the only one that has the right combination of features to be most useful to me. So, coding PHP in VS is important to me.
You can trick Visual Studio (and hopefully also Visual Web Developer) into thinking .php files are C++ with a registry hack. The syntax highlighting is close enough to be useful.
This blog post explains how to do it for all versions of VS: http://blog.cumps.be/visual-studio-2008-and-php-coloring/
I don't know about older versions, but VWD 2010 allows you to link any extension to any type of formatting in its options.
Tools->Options
click 'show all options'
Expand 'Text editor'
click on 'file extensions'
type in 'php' and select how you want it to be formatted (I recommend the Automatic Editor Selector), click Add
And there you go! Next time you load the page you will see the changes. If you don't like it, there's 20 other styles to choose from.
There is no official plugin for PHP for Visual Web Developer. I believe that this is because Microsoft would rather you use their .NET products, (notably ASP) which serves most of if not all of (I can't exactly say as I don't really use ASP as much as PHP) of the functionality of PHP.
There are however, some very good PHP IDEs out there. A list of which you Here
thx, I use the last post with "HTML format" instead "automatic editor selector"
I would recommend using Netbeans. It has code completion for PHP and runs xdebug for debugging. I've been using it for over a year and the support for PHP just keeps getting better.
Definitely worth trying.
I would recommend Visual Studio with this Extension :
http://phalanger.codeplex.com/
It is free and gives you more functionality than most of the expensive tools.
if you're using windows there's an application called notepad++ that will do syntax highlighting for dozens of languages. I used it for C but I know it has a php syntax highlighter and many more languages coming along. Check it out on sourceforge. If your using Linux or Unix you can use K Advanced Text Editor (kate). It also has a console window built in.
What I am looking is for a debugger for PHP that is as useful as the one built into Visual Studios. I searched high and low for this and there seems to be none that works well.
What I used is the PHP Designer 2007 - Personal Version 5.0.2 is a fully functional php editor, for free! from mpsoftware[dot]dk/, however I like using MSVWD a lot too, and now that I've seen how to make php files work in it, I gonna stick with that! Thanks!
btw Aptana Studio looks promising too tho
The closest Visual Studio like PHP environment I have found yet is CodeLobster. It has a free version for PHP and CSS, as well as for pay versions that include for the Pro version a plug-in for CakePHP, CodeIgniter, Drupal, Facebook, JQuery, Joomla, Smarty, Symfony, WordPress and Yii.
It isn't perfect, but it is pretty good and free for the basic version.

Can I use Ant with NetBeans PHP projects?

I would like to use Ant with some of my PHP projects but I'm not sure how. I tried creating a build script with a few targets but couldn't execute any of them from within Netbeans - there's simply no option to. Is this feature supported in this context or not? If yes, then how do I use it (I must obviously be missing something in this case). I'm using NetBeans 6.7.1 (Ant plugin is installed).
Yes you can. It's described on sun blog and according to date of the post, the posibility is here for long time
There's also this patch I created that adds ant support to PHP, enabling the build/clean functionality.
Sure there is an option or solution in netbeans (at least as external tool as in eclipse), but you could set up an continous integration system like cruiser control for build your project by version control system. There is an easy to use wrapper for cc created for PHP, named PHPunderControl. PHPUC uses Ant, PHPUnit, PHPCS as well.
Take a look at it: PHPUC

Find PHP Orphan Page

I've inherited a PHP application that has "versions" of pages (viewacct.php, viewacct2.php, viewacct_rcw.php, etc). I want to discover which of these pages are called from other pages in the application and which are not. Is there a tool available that will help with that?
Using whatever tools you would like (Find/Grep/Sed on Linux, I use Visual Studio on windows), it is just a matter of crawling your source tree for references of the filenames in each file.
Similar to FlySwat's answer: any good text editor or IDE with multi-file search should be able to help you find the orphan pages. On Mac OS X I would suggest TextWrangler(free), TextMate($), or BBEdit($$). I've had good success with each of these tools, but your mileage may vary.
If you wish to find out what pages are called by other pages, you need to look at where stuff is being called. Obviously in php code, you can only reference other files via includes or requires and the singular versions of those functions.
So if I were you I would grep your code for include and then require and attempt to make some kind of map showing what is calling what. Eventually you should end up with a pretty clear map of how the php files talk to each other. Then you will need to work out how the various points of the application talk to each other from there via HTML/AJAX etc.
Good luck. I have done it before, it takes a while, but you'll get there, just make sure you document what you find out.
You may want to try out nWire for PHP.
nWire for PHP is an innovative Eclipse plugin (works with Eclipse PDT & Zend Studio 7) which accelerates PHP development by helping developers navigate through their code and better understand the architecture of their application. nWire offers unique tools for real time code visualization, navigation and search.
nWire analyzes all the components and associations in your project. While opening a file you can immediately see where (and if) it is being used.

Categories