Php code formatter / beautifier and php beautifica

2019-01-10 05:58发布

Do you know any good tools for nicely formatting messy php code? Preferably a script for Aptana/Eclipse, but a standalone tool will do too.

14条回答
Explosion°爆炸
2楼-- · 2019-01-10 06:02

Our PHP Formatter will reliably format your code. It uses a compiler-based front end to parse the code, so it doesn't misinterpret the code and damage it. Consequently its formatted output always works.

查看更多
老娘就宠你
3楼-- · 2019-01-10 06:03

There's a pear module that formats your code. PHP Beautifier

查看更多
时光不老,我们不散
4楼-- · 2019-01-10 06:04

Use NetBeans PHP and press alt+shift+F.

查看更多
Melony?
5楼-- · 2019-01-10 06:04

What about this one:

http://universalindent.sourceforge.net/

It combines a bunch of formatters out there, and will generate the scripts you need so you can pass them out and get your team members to use them before committing next time... Though... formatters might mess up your code and render it unusable...

查看更多
手持菜刀,她持情操
6楼-- · 2019-01-10 06:06

PHP Code Beautifier is a useful free tool that should do what you're after, although their download page does require an account to be created.

The tool has been declined into 3 versions:

  • A GUI version which allow to process file visually.
  • A command line version which allow to be batched or integrated with other tools (CVS, SubVersion, IDE ...).
  • As an integrated tool of PHPEdit.

Basically, it'll turn:

if($code == BAD){$action = REWRITE;}else{$action = KEEP;}
for($i=0; $i<10;$i++){while($j>0){$j++;doCall($i+$j);if($k){$k/=10;}}}

into

if ($code == BAD) {
    $action = REWRITE;
} else {
    $action = KEEP;
}
for($i = 0; $i < 10;$i++) {
    while ($j > 0) {
        $j++;
        doCall($i + $j);
        if ($k) {
            $k /= 10;
        }
    }
}
查看更多
神经病院院长
7楼-- · 2019-01-10 06:08

I've been having a lot of trouble finding a decent free formatter for PHP as well, there are many online and command-line tools but they just don't seem to work for some reason, the results are all still full of bad indenting with combinations of tabs and spaces, and they never get the braces the way you want them!

I tried the snippet above and that didn't work for me either, indenting still full of spaces and tabs all mixed up.

So I've had a go at writing a simple one too, this one just uses all regex, no fancy compiler magic, so it's possible that it could break things, and is still very beta and being tested on various messy code. The interface is very basic at the moment too, but should improve over the next few days.

It's hardwired for MediaWiki's conventions, but you can modify it pretty easily (I may add options later).

https://www.organicdesign.co.nz/Special:CodeTidy

查看更多
登录 后发表回答