Source code formatter

Anyone know of a good PHP source code formatter?

I don’t mean color coding, but source code reformatting.

Requirements:

  • Written in PHP

  • Correctly indents using spaces (not tabs) and follows the general style/layout of the Yii codebase

  • Proper formatting and indentation of PHPDOC-style comments

Any recommendations?

Thanks!

Are you looking to format your HTML output?

If so, you can use PHP tidy functions. If tidy isn’t installed (it never is), you can use DOM functions to read and output formatted.

Something like this…might need tuning…




$dom = new DOMDocument;

$dom->validateOnParse = false;

$dom->formatOutput = true;

$dom->loadHTML($inputHtml);

$dom->saveHTML();



No, I’m looking for a PHP source code formatter - not HTML.