EDIT: To answer some of the comments - the file extension is .php, the perspective is PHP, and it is in a PHP project. I can't use different tools because this is a school project
I have Eclipse with Web Tools (so I can do web projects with JSP). I also have to use Eclipse for my PHP development (I am using it with XAMPP, if that matters). (Two different school projects.)
I have installed the plug in for PHP (in addition to XAMPP, which includes PHP itself) and it appears to work, in that I have a PHP perspective and can create a new PHP project. However, even when doing something as simple as the below, it doesn't work. Eclipse does not recognize the php tags at all.
Does anyone have any ideas what I'm missing?
<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<?php
echo "Hello World!";
?>
</body>
</html>
You have to configure the "Content-types" in Eclipse, to associate the extension of your file with the PHP editor.
This can be done in Window > Preferences > General > Content Types > Text > PHP Content Type : here, you have to add the extension of the files that contain PHP code.
Here's a screenshot of what this looks like on my current installation :
(source: pascal-martin.fr)
If you want to use the PHP Editor for one specific file, without associating its extension with the PHP Editor, you can also right-click on the file's name, and choose the right editor in the Open With menu.
ok - on a whim I decided to look for menu options that might help. And I chose Project > Clean, which rebuilds from scratch. It suddenly works!
I don't know what happened, but apparently, it was an old error that I had fixed with the right plug-in info and I just needed the project to rebuild.
Thanks for the ideas, though!
Maybe change your current Eclipse perspective into PHP?
I believe Eclipse chooses the appropriate editor (and highlighter) based on the extension of the file you're editing. Try using .php or .phtml if you can.
I think you'd better use www.aptana.org for editing web pages. Aptana is really cool in this.
If you want to keep your existing Eclipse build you can also add Aptana as a Eclipse plugin or Aptana as a standalone as #FractalizeR has suggested.
Related
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'm pretty new to php development and want to start using an IDE with syntax checking and autocompletion.
I'm used to programming java with eclipse and thought that the PDT provides similiar functionality.
In java if i type in for example: "new Arr" and press ctrl+space autocomplete suggests a list of possibilities with "new ArrayList()" on top.
but if i try the same in a php project, for example with "new mysq" and ctrl+space i get nothing. I would expect to get "new mysqli()" or similar recommended.
Is the described functionality not included in PDT? Or did i configure something wrong?
I did the "right click on project-> configure-> Add php support" but it didn't change anything.
If you would like to have some basic auto complete feature you can use NotePad++ (download) for a quick and easy starter. This is a really great minimal program that can be used very efficiently to code in many different languages. It provides huge ammount of different functions. It is a must have tool for any developer.
I used Notepad++ to write ten thousands of lines of PHP code, it worked really great for me.
Otherwise PDT also supports autocomplete. Make sure that you have a PHP project added and then your are in a PHP file (.php extension). If you have Java autocomplete working in the same project then I think that you are in a Java project, try adding a PHP project, then a new PHP source file. Then PHP autocomplete should be working well in this source file.
Make sure also that you have PHP perspective selected.
I hope you can get by now starting using PHP! Have luck and good times using this great language!
I found the solution in this question: Why does Eclipse code completion not work on some projects?
I had to manually add this:
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
to the buildpath file of my project.
I'm using Eclipse Helios on MacOSX. I'm PHP guy so i just want all PHP relateed scripts to be shown as PHP code style. I mean Code Colors.
What i'm having is: i'm developing Drupal on that Eclipse. I just wanna see php files in Drupal .module .inc .install .. whatever in future, as PHP style.
For example:
If i even make my own file extensions like filename.abcd later on, how if i what that .abcd extension files appear as PHP code style with colors?
Currently all of these not previously registered extensions are showing as just Black Lines with no color. How to do?
You can configure file associations under Windows > Preferences.
And under General > Editors > File Associations.
Simply associate the extension with the PHP Editor and it should pick up syntax highlighting for you.
For more information see:
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Freference%2Fref-13.htm
I am using Kepler and assigning the .module and .install file association did not work for me. (oddly enough, it did work for other extensions) What did work was going to help > install new software and installing the software located at this url: http://xtnd.us/downloads/eclipse
found here: http://drupal.cocomore.com/blog/using-eclipse-pdt-drupal-development
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.
Hope the title explains it all, but all I'm trying to do is open some .php files in my web-site solution and have Visual studio treat them as if they are html files. I don't need the actual PHJP code highlighted (it's only includes). The HTML syntax should be parse-able, should it not?
Tools -> Options -> Text Editor -> File Extension
in the Extension box, put .php. For the Editor, you can select HTML Editor. Click Add, then OK
You can also install the PHP Tools for Visual Studio add-in. Tools > Extension and Updates and then search for PHP online. Your first result should be this add-in.
If not, you can get it from here:
http://visualstudiogallery.msdn.microsoft.com/6eb51f05-ef01-4513-ac83-4c5f50c95fb5
If you want intellisense, debug, and other advanced functionality, you could get the php ide for VS
If all you need is syntax highlighting, check out this link. It's what I'm currently using, but doesn't have all the goodies of vs.php.
Install Phalanger.
If you're using VS2013 or older, I would recommend this extension for PHP Language support : https://visualstudiogallery.msdn.microsoft.com/2a10ba81-26c5-47d9-939b-6bcc7bbec251
For me Josh's solution didn't work and Miguel's solution needs PHP Tools which is free for 30 days but then you need to activate it.