X

An Oracle blog about NetBeans for PHP

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.  

Join the discussion

Comments ( 16 )
  • Oscar M. Wednesday, October 6, 2010

    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?


  • Patrick Webster Wednesday, October 6, 2010

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


  • lasquarte Wednesday, October 6, 2010

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


  • elrolfe Thursday, October 7, 2010

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


  • Petr Pisl Thursday, October 7, 2010

    @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.


  • Aziz Thursday, October 7, 2010

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

    Thanks


  • Azizur Rahman Thursday, October 7, 2010

    @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.


  • Jeremy Fowler Thursday, October 7, 2010

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


  • Alberto Friday, October 8, 2010

    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?


  • Anders Borg Monday, October 11, 2010

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


  • Nariman Monday, October 11, 2010

    due to problems with PHP formatter I use only 6.8 version


  • Jeremy Fowler Monday, October 11, 2010

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


  • Azuka Friday, October 15, 2010

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

    <ul>

    <?php foreach ($foo as $bar): ?>

    <li<?php echo $bar == $bar2 ? ' class="bar2"' : ''?>><?php echo $bar; ?></li>

    <?php endforeach; ?>

    </ul>

    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.


  • Marc Monday, November 8, 2010

    Any chance of adding support for the Facebook XHP extension's alternate syntax? (see http://github.com/facebook/xhp).

    It effectively allows inline HTML like this:

    ---

    echo <div>foo</div>;

    echo <div>

    foo

    </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 xhp.so 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.


  • menic Wednesday, December 1, 2010

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


  • infozone Thursday, January 13, 2011

    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.

    Thanks!


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.