Last year, I wrote an article on Coding Standards. That is all very well with your own work, but what happens when you are using code from another programmer who uses a different style from your own? The answer is phpCodeBeautifier.
Although this is an old (2003) app, I have found it useful at least once. Basically, you set a number of options in response to statements about how you want your code to look, and then run it on your file(s) and it will change the code to match your style. This means you can convert any PHP code from any style of coding to your preferred style.
For example, you can change brace styles (on the same line or on a new line), add spaces after brackets and change comment styles.
The best thing is that it is completely free and comes with GUI and command line versions.
Download here and view the manual here.
Do you use a tool, script or library in PHP that you think would be worth me blogging about? Let me know!
Related posts:
- How To Style Your Type With CSS Jennifer demonstrates how to use CSS to style type and...
- PHP Framework Plans Socially Responsible Coding Contest The Symfony PHP framework is planning a 48-hour programming competition...
- The Old Style Typeface Jennifer continues her series on font categories. Today, she looks...
- Build Your Own WordPress Themes the Easy Way A custom WordPress theme is a great service to sell...
- How to Override Inline CSS Styles Inline CSS can be applied to any HTML element using...







Hmm no updates since 2003… I wonder how it copes with PHP 5-specific syntax.
August 8th, 2005 at 12:32 pm
http://pear.php.net/package/PHP_Beautifier
August 8th, 2005 at 1:07 pm
I don’t use the phpCodeBeautifier… for a couple of reasons.
First, Zend Studio has a nice “Reformat Code” option, and secondly, there is a pretty decent pear package to allow this:
http://pear.php.net/package/PHP_Beautifier
Im surprised that you didn’t mention either of these David.
~~ Eric
August 8th, 2005 at 1:12 pm
Other disadvantages of this kind of wholesale reformatting are:
1. It does not generally play nicely with revision management systems like CVS or Subversion.
2. It makes applying patches or updates from the upstream author difficult or impossible.
In general you should aim to make as few changes as possible to code being maintained outside the scope of your project. It may not be pretty, but in the long term it will keep your life as simple as possible.
August 8th, 2005 at 2:09 pm
Updates to PHP Code Beautifier are planned for this year, including PHP5 support and lots of enhancements.
A very useful side of phpCodeBeautifier is that it can also be used from command line and could be integrated as _ for instance _ a post-commit hook on subversion or something, so that any user can work with his own layout while the repository is kept clean :)
A big time saver when you have to enter into old projects no one else is maintaining.
And it can be ran from PHPEdit…
August 8th, 2005 at 5:51 pm
Any of these will help me as I’m use to just recoding it all by hand. Lol.
August 8th, 2005 at 8:22 pm
I guess you could always change the style to yours, make your mods, then change it back to the other style when you’re done. Should alleviate most of the source control issues
August 8th, 2005 at 9:56 pm
I was tempted to make one of these a while back, I even made an automatic indenter once to indent those annoying code posts in forums which lacked proper indention. It is good to know there are more options available.
August 9th, 2005 at 3:44 am
Don’t know just how useful this could be to me? At times I need to accommodate a clients internal organisational standard, such as
class XmlWalker { …
Has to be fomatted to this instead,
class xml_walker { …
Which is annoying and difficult to maintain, so could this help me I ask? Doubtful :eek:
August 9th, 2005 at 8:05 am
If you are going to use the style with braces under the method then you want to indent the braces also, since they need to be part of the code block.
MethodName()
{
Code here;
}
Code Complete, Second Edition has a good chapter about this.
August 9th, 2005 at 2:58 pm
Oops, looks like that didn’t turn out as I expected…
August 9th, 2005 at 3:02 pm
Here is an example, its called Whitesmiths style:
http://en.wikipedia.org/wiki/Indent_style#K.26R_style
Sorry about the triple post btw.
August 9th, 2005 at 6:45 pm
For Dr Livingston:
If you work with Windows, try this:
http://www.funduc.com/search_replace.htm
Neat and simple.
August 10th, 2005 at 12:06 pm
I much prefer Polystyle (http://www.polystyle.com) myself. It has more features, it’s more customizable, is newer, integrates with a number of IDEs, and allows for entire directory parsing (biggest thing). It certainly costs more than phpCodeBeautifier, but you gotta spend money to make money and all that rot!
August 22nd, 2005 at 4:47 pm
I find the formatting of html docs most annoying. It’s difficult to find an unclosed tag for example in the mess made by wysiwyg editors. So looking for a solution to this (not hand made by me) I found tidy which I think does a good job at formatting/fixing html errors.
September 13th, 2005 at 12:15 pm
October 18th, 2005 at 11:40 pm