Deze post is geïmporteerd van de oude blog en is nog niet geconverteerd naar de nieuwe syntax.
Visual Studio is a great editor! But when editing other file formats I miss the coloring.

When working with PHP files, it's great to be able to make a solution to organize php sources, and having code open in tabs, but when they all look black and white, I find it requires more focus on my part when coding.

Long ago, I wrote a piece on getting coloring to work in Visual Studio 2002 and 2003. Somehow I managed to skip doing any PHP development during the entire lifetime of Visual Studio 2005, but recently I had to create something small, and I missed my nice colors. I tried to apply my old method in Visual Studio 2008 (Orcas), and this is the result:

Visual Studio 2008 - PHP

Looks pretty appetizing, doesn't it?

To get this in Visual Studio 2008, do the following:

  • Download and extract it somewhere.

  • Execute the preferred registry file (php_edit2008.reg for Visual Studio 2008 ofcourse).

  • This will create a File Extension association for PHP files, treating them as C++ files.

  • Copy the usertype.dat to your VS.NET directory. (default C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE)

  • Restart Visual Studio if it was opened.

  • Open a .php file and admire the colors!

For this to work, you need to have C++ support installed! Otherwise the usertype.dat file will not work, since this is specific to .cpp files. You don't need to install everything for C++, only the following will already work:

Visual Studio 2008 - Setup C++

When you look in the registry, you will see that the .php extension looks exactly like the .cpp one, you can also try experimenting with applying the .cs or .html filter to a .php file, but I found them both lacking. Using the .cs value, you will get coloring from C#, but it will also give you lots of syntax warnings. When using the .html one, it doesn't always color the entire file.

If you want to color more keywords, open up the usertype.dat file in a text editor, and simply add more words to it.

Enjoy the extra productivity gain!
Reacties: 29
  • Thanks for the update! :-)

  • Will this work for Visual Studio 2005 Pro and Exp too ?

  • 2005 Pro I would think so, as long as you install C++ support as well.

    Express, not sure. You'll have to take a look in the registry to find similar keys, and if there is one for .cpp then you're lucky. Perhaps you need to install the C++ Express Edition first, then it might work.

    If you find the .cpp key, simply edit the registry files in the zip to make sure they match the (most likely) different Express keys.

  • Just to confirm, this works like a charm in VS 2005 Pro. Thanks!

  • Dave Tigweld

    Hmmm. Now that they have totally removed syntax coloring for classic asp in VS 2008
    - I wonder if something similar could be done for that... There are a lot of us they deal both with classic asp and still.
    It stinks keeping VS2005 around for something like that.

  • Anthony Main

    Tried this in the RTM VS 2008 Team Suite Edition but no joy :(

  • Hey,

    Just confirming that this doesn't work in RTM of VS2008 Pro either

  • Well it works fine in 2008 Pro under Vista. The syntax highlighting worx for php, but if you open a php file with HTML in it,the syntax highlighting for HTML won't work.

    Still using Dreamweaver CS3 for that matter..

  • Doesn't work on my copy of VS2005 Pro (Academic). Could a third-party addon cause some kind of problem? I have AnkhSVN and VisualAssistX installed. I recently uninstalled VS.PHP (because it sucks and I wont pay for it) too.

  • Steve Boyd

    The .REG files provided in the .ZIP download only work properly on a 64 bit operating system if they are tweaked slightly. Add the "Wow6432Node" to the key path before merging the .REG. My modified .REG file for Visual Studio 2008 installed on Windows Vista x64 looks like this:

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\Languages\File Extensions\.php]

  • Neither the original, nor the version from Steve Boyd, works on my Visual Studio 2008 on Windows XP x64. any ideas? :)


    Thanks a lot

  • Ashok


    Thanks for upload.
    Will VS.PHP work with the express edition of Visual Studio as well..

    Thank you,

  • Murali

    Steve Boyd's setting for x64 machines worked for me with Vista and VS2008.


  • Very cool, thanks,

  • Ashok: VS.PHP should not work with Express editions. Even if the technical aspects are overlooked, it's not allowed by the Express edition EULA.

  • Strange.
    Worked for me with VS2005 but not with VS2008.
    WinXP64 - and used Steve Boyd's registry trick. Even tried registering *.php files by hand in VS2008, but still no luck.
    Ah well. Now I can keep VS2005 around for Fortran AND php....

    Thanks for the files.

  • Works a charm in VS2008. Many thanks for taking the time to do this!

  • Matthew McKenzie

    Great, wht can't we do this for other extensions as well ? I want .win files to highlight as .c and this should be a standard option in VS.

  • Andre Steenveld

    Great tool! even works for yacc (*.y) and lex (*.l) files.

    Thanks a lot, this makes life just a little bit easier. ;-)

  • Tim

    Thanks just what I needed

  • Orn

    Works great VS2005 and vs2008, thanks a lot.

  • Stuart

    This can be done for other file types, providing you know which formatting type you are after.
    Go to Tools->Options.
    Expand Text Editor.
    Click File Extension.
    Fill in the form on the right (enter extension, select Editor) then click Add.

  • Jesse

    #28 - works beatifully. The author should really add this advice to his post as this is much easier!

  • Baris Ergin

    Thank you for this information, you light my day!

  • Well, considering that PHP is a direct descendant of C/C++ (not to mention a couple others), it really is no wonder that using C++ code coloring (or a derivative of) would work. This is much appreciated. :)

  • screwed

    yay. now Visual Studio doesn't work at all.

  • Worked perfectly for VS 2008 Pro. Thanks!!

  • d

    The php-vs.rar solution did not work for me, nor did the additional registry addition/merge. However, the option to add an extension in VS 2008 from Stuart zegt worked like a charm! (VS 2008 TS/Vista 64-bit)

  • Reageer
    Items aangeduid met * zijn verplicht. (Naam, Email, Commentaar)
    Enkele items ontbreken of zijn fout ingevuld.
    Om zeker te zijn dat je geen computer bent, typ de onderstaande tekst over.