7

Are there any command line (not interactive, not web-based) tools that will reformat (pretty-print) PHP and Javascript code?

rwallace
  • 31,405
  • 40
  • 123
  • 242

3 Answers3

7

PHP_ Beautifier is very outdated! For a more modern approach try php-cs-fixer

Example command: php-cs-fixer fix --rules=@PSR2 path/to/php/src

A second alternative is PHP_CodeSniffer

Example command: phpcbf --standard=PSR2 path/to/php/src

nltw
  • 17
  • 6
Moak
  • 12,596
  • 27
  • 111
  • 166
3

For a PHP beautifier, you can also use this pear package PHP_Beautyfier, which can either be called from the command line or instantiated within your own PHP code. For the Javascript one instead, find an open discussion here

Community
  • 1
  • 1
Andrea Fiore
  • 1,628
  • 2
  • 14
  • 18
1

I wrote an article explaining how to build a command-line JavaScript beautifier implemented in JavaScript. The best part - it takes under 5 minutes to do it, YMMV.

Cheers!
Shonzilla

John
  • 15,418
  • 12
  • 44
  • 65
Shonzilla
  • 7,926
  • 1
  • 23
  • 25