PHP Code-Beautifier Tool

Posted by Tim Koschützki, on May 01, 2007 - in Coding Techniques & Tools » Tools

Today I discovered a good tool for beautifying existing PHP Code. It works via a web interface. You can either upload a script or directly input it. The code is beautified according to the PHP PEAR Standard Requirements. It does not change or debug your code in any way. What it does is the following:

* Tries to set missing curly braces around single conditional statements. This may not work in all situations.
* Indents with four spaces.
* Uses "one true brace" style in function definitions.
* Sets one space between control keyword and condition.
* Removes space between function calls, parenthesis and beginning of argument list.

Nice tool!

You can download it here.

Print this Post | Digg This | Stumble It | Delicious

7 Comments

[...] PHP-Coding-Practices.com, there’s a new post pointing out a code beautification tool Tim dug up the (aptly named) “PHP Code [...]

medyk on May 12, 2007:

It has one big flaw.. it works in iso-8859-1 encoding instead of utf-8 - it will change all non iso characters in code..

Tim Koschuetzki on May 15, 2007:

Yeah checked that out myself. I will most likely email the developer about it.

Other than that it's a good tool!

Bidfreelancers on May 31, 2007:

Can it work on all php files in one folder or we have to upload one file by file.

Tim Koschuetzki on May 31, 2007:

Unfortunately it can't yet. However, I will modify it so that it will be possible. I scheduled this for Sunday. Can't work on it today, because I will need to do something for my full-time job. :/

Visitor302 on Aug 05, 2007:

Your site found in Google: http://google.com/search?q=jxt

kvz on Jul 29, 2008:

Another one is PHP_Beautifier. Not perfect, but might help in some cases:

pear install PHP_Beautifier
# note: you may need to first run
pear config-set preferred_state beta

php_beautifier \
--filters "\
IndentStyles(style=k&r) \
NewLines(before=if:switch:T_CLASS,after=function) \
Pear(add_header=apache) \
ArrayNested() \
Lowercase()\
-f myfile.php

Add a comment