Visual Studio 2008 and PHP Coloring

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 vs-php.zip 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!

31 reacties op “Visual Studio 2008 and PHP Coloring”

  1. [...] linked my article, just informing you I just posted an update for Visual Studio 2008 :) Found at: http://blog.cumps.be/visual-studio-2008-and-php-coloring/ Best [...]

  2. pandasan zegt:

    Thanks for the update! :-)

  3. [...] & PHP Kolorowanie skÅ‚adni PHP w Visual Studio? – jasne czemu nie! David Cumps w na swoim blogu pokazuje co musimy zrobić aby to [...]

  4. Anjanesh zegt:

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

  5. David Cumps zegt:

    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.

  6. [...] been update from the original author David Cumps.Now you can obtain the same behaviuor on VS2008:http://blog.cumps.be/visual-studio-2008-and-php-coloring/  Filed under: Visual Studio 2005, PHP, Visual Studio 2008 Attachment(s): [...]

  7. Julian zegt:

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

  8. Dave Tigweld zegt:

    Hmmm. Now that they have totally removed syntax coloring for classic asp in VS 2008
    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=290845
    – I wonder if something similar could be done for that… There are a lot of us they deal both with classic asp and asp.net still.
    It stinks keeping VS2005 around for something like that.

  9. Anthony Main zegt:

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

  10. Wingot zegt:

    Hey,

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

  11. Barry zegt:

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

  12. Yuyo zegt:

    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.

  13. Steve Boyd zegt:

    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]
    @=”{B2F072B0-ABC1-11D0-9D62-00C04FD9DFD9}”

  14. [...] did I edit my PHP files? Turns out that David Clump has added coloring support for PHP Visual Studio 2008! Notepad2 also supports PHP coloring but doesn’t copy/paste into [...]

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

  16. CISSE zegt:

    Thanks a lot

  17. Ashok zegt:

    Hi,

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

    Thank you,
    Ashok

  18. Murali zegt:

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

    Thanks.

  19. Adam Sporka zegt:

    Very cool, thanks,
    Adam.

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

  21. Dan Revelle zegt:

    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.

  22. foxbat zegt:

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

  23. Matthew McKenzie zegt:

    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.

  24. Andre Steenveld zegt:

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

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

  25. Tim zegt:

    Thanks just what I needed

  26. Orn zegt:

    Works great VS2005 and vs2008, thanks a lot.

  27. Stuart zegt:

    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.

  28. Jesse zegt:

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

  29. Baris Ergin zegt:

    Thank you for this information, you light my day!

  30. 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. :)

Reageer