Formatting PHP and HTML

I have made a few enhancements and fixes in the formatting area, where PHP and HTML is used in one file together. It's not ideal and probably there are many cases, when it doesn't work as you want. So if you find a case, when the formatter doesn't work correctly, please file a new bug in our Bugzilla.

Probably the most visible change is that the formatter in NetBeans 6.9 and NetBeans 6.9.1 tried to place the close PHP tag on the same column as open PHP tag is. Now the formatter treat the open and close PHP tags as html tags.

 The second improvement is that the formatter and indentation engine have now better support for alternative syntax.

Some times users wrote me that the formatter worked better in NetBeans 6.8. This is not true. There wasn't a formatter in NetBeans 6.8, there was only indenter. So it "just" moved the beginning of lines.

I don't claim that current formatter is perfect and that the formatter works perfectly. It's not easy task and there will be always cases, when it will no work perfectly. But you can help us to eliminate them.  


Would it be difficulat to have an option where the php and html are indented separately from each other? And one to keep opening and closing php tags unindented?

Posted by Oscar M. on October 06, 2010 at 10:09 AM CEST #

It would be nice to have syntax highlighting of HTML within PHP Heredocs.

Posted by Patrick Webster on October 06, 2010 at 11:56 AM CEST #

i'm sorry for newbie question, but how can i install this plugin?

Posted by lasquarte on October 06, 2010 at 12:57 PM CEST #

tried plugins->updates to install.. no success. how do you install it?

Posted by elrolfe on October 07, 2010 at 02:32 AM CEST #

@Oscar M.: Could you please add examples?

@Patrick Webster: I was thinking about this, is not so difficult, but then I thought that it will be misleading. Probably another background to make difference from html.

@lasquarte & elfolfe: This is a part of php editor and it's available in development builds now. You can not download it now as a plugin. You have to use dev build or wait for the release.

Posted by Petr Pisl on October 07, 2010 at 06:35 AM CEST #

I like Netbeans 6.8 indenter but not like 6.9 formartter, please insert a option to activate and deactivate formatter.


Posted by Aziz on October 07, 2010 at 07:46 AM CEST #

@Petr Pisl is there a way I can set up my NetBeans to auto install the daily build?

This would help save time.

Rather than:

visit download site -> select latest -> download -> wait for download (move on to something, may be un-install current build)-> wait long time -> come back -> run installer -> run IDE

One would do:

run NetBeans -> new build ready -> Download in background -> update (restart?) -> fire IDE.

Posted by Azizur Rahman on October 07, 2010 at 09:38 AM CEST #

How about adding PHP Code Sniffer support and have Netbeans auto-format based on the coding standard set for the project?

Posted by Jeremy Fowler on October 07, 2010 at 11:36 AM CEST #

Will it be possible to have diferent indentation rules for PHP and HTML parts (ie. use spaces for the PHP parts, but use tabs for HTML parts).
I sometimes use 4 spaces for PHP code indenting but would like to use tabs in the HTML parts to save a little bandwidth.
Or maybe that option is already available and I didn't find it?

Posted by Alberto on October 08, 2010 at 02:58 PM CEST #

My message was considered spam for some reason. Weird. Goodday to you all in any case.

Posted by Anders Borg on October 11, 2010 at 01:35 PM CEST #

due to problems with PHP formatter I use only 6.8 version

Posted by Nariman on October 11, 2010 at 04:13 PM CEST #

I personally prefer to keep it all on a single line:

<?php if ($this->picture == NULL): ?>

<?php else: ?>

<?php endif; ?>

Would be nice if the closing ?> tag would auto-complete like other html end tags...

Posted by Jeremy Fowler on October 11, 2010 at 04:23 PM CEST #

I'm having some problems with the latest nightly's formatter. In HTML5 I have something like

<?php foreach ($foo as $bar): ?>
<li<?php echo $bar == $bar2 ? ' class="bar2"' : ''?>><?php echo $bar; ?></li>
<?php endforeach; ?>

I get all the PHP inside the UL highlighted as invalid. Even the <li<?php... is not recognized as the start of a valid tag.

I think something recently introduced (not sure what, but possibly HTML5 formatting) doesn't consider that HTML might be mixed with other stuff.

Posted by Azuka on October 15, 2010 at 03:12 PM CEST #

Any chance of adding support for the Facebook XHP extension's alternate syntax? (see

It effectively allows inline HTML like this:


echo <div>foo</div>;
echo <div>

$foo = 'bar';

echo <div>{$foo}</div>;
echo <div>{substr($foo, 0, 1)}</div>;


The benefits are that it enforces proper tag closure, etc.

Although the extension is enabled in my php.ini, NetBeans PHP (6.9.1 and 7.0 M2) flag these lines as syntax errors although they are executed just fine by PHP.

Posted by Marc on November 08, 2010 at 02:24 AM CET #

Is it possible to change formatting to the nb 6.8 way? I want to nb format braces in new line, instead of putting it at the end of ie. if() instruction...

Posted by menic on December 01, 2010 at 06:20 AM CET #

I second the request to add XHP support.
Also, would it be possible to make templates obey formatting rules? Now if I let's say set braces to be placed on new lines, templates still extend like

class Foo {

if($foo == $bar) {
} else {

and so on. To change that I must change every template manually; while that should be done only once, would be much better to have them autoformatted according to global rules.


Posted by infozone on January 13, 2011 at 04:12 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed

This blogs is written by NetBeans developers who contribute to the PHP support mainly.


« July 2016