Visual Studio PHP Tools not formatting code - php

I'm writing php in Visual Studio using the PHP Tools extension. The code formatting of the PHP Tools doesn't seem to be working.
The formatting option is available in the options menu:
And I have tried linking the php-extension to the PHP Editor:
But nothing seems to work. When I try right-clicking a php document and choose Formatting and Validation it goes straight to HTML (Web Forms).
The problem seems to lie with Visual Studio not recognizing php as a language. Anybody an idea? Thanks in advance.

Related

VSCode and PHP (hurdles) [duplicate]

First let me say I've never used PHP but I'm looking to learn it, so my question is this how do you use PHP within Visual Studio Ultimate? is it similar to how you declare JQuery i.e
$(document).ready(function ()
{
// Code goes here?
});
I've done multiple searches on Google, but I don't get the answer I'm looking for.
Or do I need a complete different bit of software to use it?
By default VS is not made to run PHP, but you can do it with extensions:
You can install an add-on with the extension manager, PHP Tools for Visual Studio.
If you want to install it inside VS, go to Tools > Extension Manager > Online Gallery > Search for PHP where you will find PHP Tools (the link above) for Visual Studio. Also you have VS.Php for Visual Studio. Both are not free.
You have also a cool PHP compiler called Phalanger:
If I'm not mistaken, the code you wrote above is JavaScript (jQuery) and not PHP.
If you want cool standalone IDE's for PHP: (Free)
Netbeans: https://netbeans.org/downloads/start.html?platform=windows&lang=en&option=php
Eclipse: http://www.eclipse.org/downloads/packages/eclipse-php-developers/heliosr
Maybe we should help you with a big misunderstanding on your side first: PHP is (like ASP.NET or whatever you used to far) a server side language while javascript is client side.
This means that PHP will run on your webserver and create a HTML page dynamically which is then sent to the browser. Javascript in turn is embedded (either directly or as a referenced file) into this HTML page and runs in the browser.
Maybe you can now understand why your approach so far could never work out.
Try Visual Studio Code. Very good support for PHP and other languages directly or via extensions.
It can not replace power of Visual Studio but it is powerful addition to Visual Studio.
And you can run it on all OS (Windows, Linux, Mac...).
https://code.visualstudio.com/
Maybe it's possible to debug PHP on Visual Studio, but it's simpler and more logical to use Eclipse PDT or Netbeans IDE for your PHP projects, aside from Visual Studio if you need to use both technologies from two different vendors.
Here are some options:
Visual Studio PHP (VS.Php).
PHP Tools for Visual Studio by DEVSENSE.
Or you can check this list of PHP editor reviews.
I don't understand how other answers don't answer the original question about how to use PHP (not very consistent with the title).
PHP files or PHP code embedded in HTML code start always with the tag <?php and ends with ?>.
You can embed PHP code inside HTML like this (you have to save the file using .php extension to let PHP server recognize and process it, ie: index.php):
<body>
<?php echo "<div>Hello World!</div>" ?>
</body>
or you can use a whole php file, ie: test.php:
<?php
$mycontent = "Hello World!";
echo "<div>$mycontent</div>";
?> // is not mandatory to put this at the end of the file
there's no document.ready in PHP, the scripts are processed when they are invoked from the browser or from another PHP file.

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

How to use PHP with Visual Studio

First let me say I've never used PHP but I'm looking to learn it, so my question is this how do you use PHP within Visual Studio Ultimate? is it similar to how you declare JQuery i.e
$(document).ready(function ()
{
// Code goes here?
});
I've done multiple searches on Google, but I don't get the answer I'm looking for.
Or do I need a complete different bit of software to use it?
By default VS is not made to run PHP, but you can do it with extensions:
You can install an add-on with the extension manager, PHP Tools for Visual Studio.
If you want to install it inside VS, go to Tools > Extension Manager > Online Gallery > Search for PHP where you will find PHP Tools (the link above) for Visual Studio. Also you have VS.Php for Visual Studio. Both are not free.
You have also a cool PHP compiler called Phalanger:
If I'm not mistaken, the code you wrote above is JavaScript (jQuery) and not PHP.
If you want cool standalone IDE's for PHP: (Free)
Netbeans: https://netbeans.org/downloads/start.html?platform=windows&lang=en&option=php
Eclipse: http://www.eclipse.org/downloads/packages/eclipse-php-developers/heliosr
Maybe we should help you with a big misunderstanding on your side first: PHP is (like ASP.NET or whatever you used to far) a server side language while javascript is client side.
This means that PHP will run on your webserver and create a HTML page dynamically which is then sent to the browser. Javascript in turn is embedded (either directly or as a referenced file) into this HTML page and runs in the browser.
Maybe you can now understand why your approach so far could never work out.
Try Visual Studio Code. Very good support for PHP and other languages directly or via extensions.
It can not replace power of Visual Studio but it is powerful addition to Visual Studio.
And you can run it on all OS (Windows, Linux, Mac...).
https://code.visualstudio.com/
Maybe it's possible to debug PHP on Visual Studio, but it's simpler and more logical to use Eclipse PDT or Netbeans IDE for your PHP projects, aside from Visual Studio if you need to use both technologies from two different vendors.
Here are some options:
Visual Studio PHP (VS.Php).
PHP Tools for Visual Studio by DEVSENSE.
Or you can check this list of PHP editor reviews.
I don't understand how other answers don't answer the original question about how to use PHP (not very consistent with the title).
PHP files or PHP code embedded in HTML code start always with the tag <?php and ends with ?>.
You can embed PHP code inside HTML like this (you have to save the file using .php extension to let PHP server recognize and process it, ie: index.php):
<body>
<?php echo "<div>Hello World!</div>" ?>
</body>
or you can use a whole php file, ie: test.php:
<?php
$mycontent = "Hello World!";
echo "<div>$mycontent</div>";
?> // is not mandatory to put this at the end of the file
there's no document.ready in PHP, the scripts are processed when they are invoked from the browser or from another PHP file.

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