Php code formatter / beautifier and php beautification in general

editor, php

Solution

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;
        }
    }
}

Problem

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.

Original source