5

I have a folder of PHP files. The source code to these files is compressed into a few lines with no line breaks or other conventional formatting and is extremely hard to read.

I have found several online tools to make the source readable, but they all do this is one by one: http://thephppro.com/tools/beautify.php http://www.prettyprinter.de/

How to format source code in batch? Is there any way to accomplish the process of making a folder/subfolder of PHP source code readable more efficiently? Is there any IDE that will format files in batch mode, or another php script/cli tool that I am unaware of which can perform this operation?

Daniel Brose
  • 1,394
  • 10
  • 24
timelfelt
  • 680
  • 1
  • 11
  • 26
  • This site is bonkers. "Instead describe the problem and what has been done to solve it". I have a specific problem - here are the tools I tried to use to solve my problem. How is this off topic? Whereas this post is literally just asking for tools https://stackoverflow.com/questions/137102/whats-the-best-visual-merge-tool-for-git – timelfelt Jul 21 '17 at 13:54

1 Answers1

4

Have you tried PHP Beautifier?

DCoder
  • 12,962
  • 4
  • 40
  • 62
  • 1
    Beautify all files and recreate the dir structure on ./myprogram-beautified/ php_beautifier -r "*.php" ./myprogram-beautified/ – timelfelt Apr 02 '12 at 14:53
  • To add on to @timelf123's post, navigate to the project path - `cd /path/to/project` - then run - `php_beautifier -r "*.php" /path/to/project` - You could also run `php_beautifier -rv "*.php" /path/to/project` to get a verbose output. May need to run as admin/root(sudo) – Magictallguy Apr 04 '17 at 02:53
  • Use [atom-beautify](https://atom.io/packages/atom-beautify) with atom IDE for Beautify many file formats. – NiroshanJ Jul 24 '17 at 11:21
  • 1
    Please try [PHP-CS-Fixer](http://cs.sensiolabs.org/), which is a more up-to-date and powerful tool. Not only beautifying the code, but also fixing it to following PHP code standards. Though it takes a little bit time to get started with. – hailong Apr 19 '18 at 14:29
  • I don't know why, it seems to remove .htaccess from result – The concise May 09 '22 at 02:24