How can I make visual studio highlight .php files - php

Hope the title explains it all, but all I'm trying to do is open some .php files in my web-site solution and have Visual studio treat them as if they are html files. I don't need the actual PHJP code highlighted (it's only includes). The HTML syntax should be parse-able, should it not?

Tools -> Options -> Text Editor -> File Extension
in the Extension box, put .php. For the Editor, you can select HTML Editor. Click Add, then OK

You can also install the PHP Tools for Visual Studio add-in. Tools > Extension and Updates and then search for PHP online. Your first result should be this add-in.
If not, you can get it from here:
http://visualstudiogallery.msdn.microsoft.com/6eb51f05-ef01-4513-ac83-4c5f50c95fb5

If you want intellisense, debug, and other advanced functionality, you could get the php ide for VS
If all you need is syntax highlighting, check out this link. It's what I'm currently using, but doesn't have all the goodies of vs.php.

Install Phalanger.

If you're using VS2013 or older, I would recommend this extension for PHP Language support : https://visualstudiogallery.msdn.microsoft.com/2a10ba81-26c5-47d9-939b-6bcc7bbec251
For me Josh's solution didn't work and Miguel's solution needs PHP Tools which is free for 30 days but then you need to activate it.

Related

PHP Tools extension and HTML intellisense

I got the PHP Tools professional version, but realized that it only has php intellisense, and that it only has color highlighting for HTML. While html itself admittedly isn't difficult, I would like to have intellisense for it as well.
Does anyone know of a way that I can link both PHP and HTML intellisense to a single extension?
I tried to go to options->Text Editor->File Extension and set the php extension to the HTML editor, but it removed the PHP Tools intellisense and just replaced it with the HTML one. What I'd really like is to keep the php while adding (not replacing) html editor tools.
This is known limitation of external editors for Visual Studio. Anyway according to PHP Tools features page (just updated), the work is in progress. For now, it isn't possible to 'mix' two languages like HTML & PHP.
Look at this thread:
http://support.devsense.com/viewtopic.php?f=21&t=987
Seems to come soon :-).

Is it possible to auto format PHP in Sublime Text 2?

In Sublime Text 2, I am trying to type the code and have auto format command to rearrange and auto indent source code. If it is not possible to have a automatic formatter, would be nice to have a shortcut command to do it.
I am searching for something else besides the built-in "Reindent" option and the hard-to-make-work "PHP Beautifier" plugin.
I would like to know if someone found any nice auto formatter for PHP: any formatter that won't mess our PHP code. JSFormat seems to be not useful.
Is there any easy to "install and use" plugin?
PHPTidy is definitely good choice for PHP code formatting in SublimeText2.
You need to install package control package to enable you to install packaged in sublime text: link.
ctrl+shift+p -> type -> Package Control: Install Package
search for phpTidy -> hit enter
that is it - now you can format your code in WordPress coding convention.
How to format you code:
ctrl+shift+p -> type -> tidy -> Hit Enter
ctrl+alt+t
Hope this help.
There is a PHP code formatter named PhpBeautifier. Here you can find a Sublime Text plugin for this program and you can also install it via package control.
I have this set up as a keybind:
[
{
"keys": ["alt+shift+f"], "command": "reindent",
"args": {"single_line": false}
}
]
If you're looking for a bit more than that there is Tidy PHP under package management.
Update: Been some time, I'm now using PHP Coding Standards along with PHP CS Fixer which automates a lot of the cleanup done by autoformatting. This takes a fair bit of work / understanding of php cs to setup but its not too hard, and well worth it. Link
I've been searching this before also, but with no avail. Sublime text 2 probably doesn't support formatting PHP code natively. I have looked into ST2 packages - http://wbond.net/sublime_packages/community, but there is also nothing. Probably you'll have to do this in another editor.
Of course it would be nice, if someone would write a package for this, 'cause packages for formatting JS, JSON, HTML.. already exist.
This is an old subject, but as I found it via Google, here's an answer :
You can use the phpfmt plugin for Sublime Text 3, and configure it to respect code conventions (Such as PSR-0, PSR-1 or PSR-2).
The files will be beautified on save.
I'm using sublimetext-codeformatter
It supports PHP, JavaScript/JSON, HTML, CSS, SCSS, Python, Visual Basic/VBScript and maybe more in the feature. For PHP formatting it uses a fork of the phpfmt which works well. All languages-specific formatting can be set in one config file.
Not sure if this is what you are looking for, but are you aware that when you save your file as .php, Sublime Text 2 automatically highlights and indents according to its built in PHP rules. You can also select this from going to View, and then Syntax, and selecting PHP. But again, this is automatically done when you save the file as .php.

PHP intellisense on Visual Studio - Is it possible?

Nothing compares to Visual Studio. Infact it is the reason why I develop using Asp.Net. But once in a while I encounter a client who specifically wants a solution authored in PHP.
All PHP IDEs(Free) I have used lack a vital feature available in Visual Studio that I love so much - INTELLISENSE. So is there a free way to enable PHP intellisense on Visual Studio ?
You can use VS.PHP to get php in similar VS environment. (Commercial)
Introducing the next generation of PHP
development tool Rich intellisense and
debugging support Easy to get started
with built-in PHP web server
Or Free alternative:
Php4VS
The Php4VS is a Package for Visual
studio which aims to do the same thing
as some others do, but with one
difference : for FREE !
Use Netbeans as an "extension".
1. install netbeans
2. In visual studio, right-click on a php file and select open with. Add new.., and select Netbeans.exe in the bin folder in the Netbeans installation folder. Click OK and also set as default.
Now, just for php files, they'll open in netbeans. It's probably the best solution for now especially with the Express editions which don't allow 3rd party extensions.
Note: you most likely want to set netbeans to use utf-8 so you won't have problems including php files in other files. to do that:
Go to "etc" folder in Netbeans Installatin folder. Open netbeans.conf file and add on netbeans_default_options following line:
-J-Dfile.encoding=UTF-8
What about PHP tools for Visual Studio?
Visual Studio does not natively support PHP as a language. However there do appear to be third party which provide extensions for PHP that provide intellisense (among other features)
http://www.jcxsoftware.com/vs.php
I was having an issue when converting my HTML files to PHP, there was no intellisense available at all - not even for the HTML portions. To fix this, R-click the PHP file in Solution Explorer and select Open With... , then select "HTML Editor" and "Set as Default". It won't give PHP support, but it brought back HTML intellisense for me.

Enable PHP highlights in VS 2010?

I've heard that Visual Studio 2010 Beta 2 has support for PHP. When I load a PHP file though, it has nothing highlighted and is nothing more than a glorified text editor.
Is there a way to enable it?
You can enable syntax highlighting for php files using a simple hack in Visual Studio 2010 (might also work for earlier versions)
Open Tools -> Options dialog from the menu, and select Text Editor -> File Associations on the left. Add php as a new extension and select 'Microsoft Visual C++' in the adjacent combo box. Apply and now you and open and edit any php file in Visual Studio with Syntax highlighting and code folding. The only problem come is when the file has mixed php and html code. It does not look really good and editing is painful.
I have tried VS.php, and I am certainly not impressed. The only thing it can add to visual studio is creating a php project easily, otherwise, I haven't been able to find it any more useful.
As far as I know, we don't do PHP support out of the box. You probably need a third-party component such as this one: http://www.jcxsoftware.com/vs.php
I've found by using the VS2010 script editor for PHP it does 90% of what I wanted.
As Samnan states - goto Open Tools -> Options dialog from the menu, and select Text Editor -> File Associations
and told VS2010 to use its script editor
Also XRefresh plugin for firefox is quite handy for quickly viewing code changes on a second monitor running firefox.
On Microsoft Connect, it seems that this is a feature request. And they've talked about it on MSDN. But so far, syntax highlighting doesn't seem to be a builtin feature just yet. Though, Expression Web 2 and 3 do have IntelliSense in the HTML designer, we could be seeing native syntax highlighting in the Visual Studio 2010 RTM come March.
Hope this helps.
I've heard rumors about them adding it in the final release, however there is no native support for PHP within the beta right now.

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.

Categories