61

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?

4
  • 4
    Why don't you want to use a simple editor like notepad++ or sublimetext or vi ? A great advantage of PHP is that you don't have to manage compilations or builds. May 10, 2012 at 7:26
  • 6
    one can be used to work in Visual Studio; totally understand. Try visualstudiogallery.msdn.microsoft.com/… Mar 6, 2013 at 15:22
  • Here is a solution at here (WebMatrix, free) : superuser.com/questions/644060/… Jun 17, 2015 at 12:03
  • 3
    this question references jQuery - a client side JavaScript library - i.e. it runs after HTML has been formulated and sent from the server to the browser... but PHP runs server-side, and is used to create the HTML code that will be sent down to the browser.. so, that is no small distinction - and thus the two technologies are nowhere near similar
    – bkwdesign
    Dec 29, 2015 at 22:16

6 Answers 6

74

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: Phalanger PHP Compiler

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)

3
  • is this support PHP MVC??
    – AminM
    Apr 27, 2016 at 6:13
  • was getting error on netbeans dl. New link? netbeans.org/downloads Sep 21, 2016 at 17:42
  • It is currently free to use Visual Studio CODE and the FREE version of PHP Tools for Visual Studio CODE. It probably makes more sense to use one of the above mentioned IDE's instead.
    – Mike Grimm
    Dec 6, 2019 at 17:56
15

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.

2
  • 11
    I just came across this and wanted to add a clarification for future visitors. PHP is a server-side scripting language, while ASP.Net is a server-side Web application framework. They are not comparable. One is a programming language, the other is a framework. ASP.Net allows you to use several different programming languages, such as C# and VB, to develop your web site/application.
    – Anders
    Jun 7, 2016 at 15:59
  • 2
    @Anders You are absolutely right. I decided to keep it simple in order to concentrate on what seemed relevant to me. In this case the difference between server side and client side execution. Feb 17, 2019 at 17:45
9

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/

3
  • 2
    Visual Studio Code is quickly becoming the "catch-all" for things Visual Studio doesn't support. Like GoLang. Very versatile.
    – rdtsc
    Dec 7, 2016 at 19:16
  • VSCode still doesn't support proper code formatting, it always insist on expanding your code like ruining your CSS and Javascript. but still works better than netbeans which still doesn't have vertical selection and doesn't even format HTML properly.
    – AaA
    Sep 5, 2019 at 8:20
  • (I'm contributor to the extension below) The complete PHP language support (debugging, IntelliSense, test explorer, code analysis, formatting, ...) provided with additional extension marketplace.visualstudio.com/… Jun 23, 2021 at 19:32
8

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.

1
  • 10
    Off topic. The question is how to use PHP with visual studio. Been using VS php for 6 years, it's stellar and worth the price.
    – Max
    Nov 12, 2015 at 23:28
7

Here are some options:

Or you can check this list of PHP editor reviews.

4
  • 2
    I hardly not recommend VS.PHP This thing is really buggy and cause frequent fatal crashes of VS (2013 x86 on W7 machine)
    – eka808
    Jul 23, 2016 at 15:37
  • 2
    These both are not free, are there any tools which are free?
    – user6856823
    Dec 1, 2016 at 13:00
  • Visual Studio PHP link is going to an scam website now
    – AaA
    Sep 5, 2019 at 8:21
  • @AaA: link updated to marketplace.visualstudio.com/…
    – Revious
    Sep 5, 2019 at 9:29
3

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.

2
  • Ultimately I think the author wants to know how he can start using PHP within Visual Studio, like with compiling and debugging support.
    – Crono
    May 23, 2017 at 12:12
  • 3
    @Crono Author actually doesn't have a clue about PHP and what it does. But this question was back in 2012. May 29, 2017 at 6:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.