I have to create a project in php. I am very used to the visual studio ide therefore it will be very nice if I could program my site in there. There is a plug in that enables you to create php projects in visual studio located in here.
When I open a php file it is great, I get the intelicence and code coloring.
the problem is that when I see the other parts of that page (html, javascript, css etc) I dont get the intelligence nor the dom help where I can select elements etc.
so javascript appears as:
to resolve this problem of the javascript and intelicence I told visual studio to treat php files as html by doing:
Tools --> Options --> Text Editor --> File Extension
after doing that I am able to get the intelicence on the html, javascript, css etc. but then I lose the php functionality.
It will be very nice if I could make this work with visual studio. I have to do this project in php I wish I had to do it on asp. So I was thinking that maybe I could combine the editors since the php editor only cares about what is inside and html about the rest...
As part of the popular and excellent MVC pattern, it is best to separate your HTML and PHP. This will solve more problems than just editor support.
Related
I am using Visual Studio Code on a Mac to work on WordPress applications.
Is there a way to make Visual Studio Code recognize HTML and use it's features (mainly autocompletion) inside PHP files?
I've searched for this answer before but just get told to Go to Visual Studio Code Settings: File >> Preferences >> User Settings
// Place your settings in this file to overwrite the default settings
{
// Configure file associations to languages (e.g. "*.extension": "html"). These have precedence over the default associations of the languages installed.
"files.associations": {"*.php": "html"}
}
But doing this makes you lose all PHP support and autocompletion.
I wish Microsoft would realize that PHP developers commonly use PHP and HTML together when creating applications/websites. I would love to use VS Code instead of the magnificent but expensive PHP storm if possible.
You can install this plugin:
PHP Intelephense
As far as I can tell, it does. Take a look at this php file I have created in VS Code (no extensions), with HTML inside the file with syntax highlighting for both languages.
There is a button (It should say the word PHP) in the bottom right corner of the screen that allows you to switch the syntax highlighting and autocompletion to another language, and while this does temporarily turn off PHP syntax, it will allow you to code in HTML a lot easier.
You can enable html support in any language by adding the following to your settings.json file:
"emmet.includeLanguages": {
"your-language": "html",
"rust": "html",
"php": "html",
"javascript": "html",
}
Very easy solution
Search emmet in settings and remove php form Emmet: Exclude Languages list
This will definitely work for everyone
I also faced this genuine concern while learning PHP, and the only solution I came up with at the moment is clicking on PHP button on bottom right corner of VS Code screen.
I am attaching the screenshot below with that PHP button highlighted so you would be able to locate it easily. Once clicked it will ask for a language you want autocomplete to work on, select HTML and it would start autocompleting html, click again to enable PHP autocomplete.
I also happened to come across GitHub Pilot Extension, you need to be a student for availing this service for free or you'll have to buy membership, It is a good tool for auto complete although that is not the gist of it's use, It is something great invented for learners and also professional coders.
I used to use PHPEd and it has content-aware autocomplete. It knows the content that your cursor is in: php, html, css, js, etc and suggests tags/attributes/functions/etc based on the language where the cursor is. The entire problem with VSCode is its decidedly unintelligent “intellisense” that relies wholly on what language the document is defined as. Any IDE worth its salt is going to have content aware auto-completion. The only satisfactory answer to your question is make your own snippets and turn off emmet and php auto-completion.
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.
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 :-).
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.
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.