PHPB 1.0.2 is released, and it has a new feature: Command Line Interface, yep, you can use PHPB to beautify your php code from command line now!
Here are some examples:
phpb -i test.php -o test_output.php
I’ve finally added a Command Line Interface (CLI) to PHPB. You can use it as a stand-alone script. It’s also available as a php package, so you can use it in your own scripts.
For the impatient:
How to install PHPB CLI on Linux/Unix/MacOS:
PHPB is written in PHP, so you need PHP 7.2 or higher installed on your computer. Most Linux distros come with PHP pre-installed, but the version is usually very old. So you might want to install it from an updated source like PPA, or directly from the PHP website (see https://www.php.net/manual/en/install.php).
Once you have updated your PHP installation, you can download and install the latest version of PHPB from its Github repository:
$ git clone https://github.com/alecjacobson/PHP-Beautifier.git
$ cd PHP-Beautifier
$ ./bin/phpb -v
PHPB now has a command line interface. You can use it to beautify PHP files, and you can use it to call PHPB from other scripts and programs.
The syntax is:
phpb.php [options] filename1 filename2 …
If no filenames are given, then standard input is read and standard output is used for the result. If one or more filenames are given, then they are processed in order. If the -o option is given, then the result is written to standard output. Otherwise each file is overwritten with its beautified form. Any errors encountered during processing will be written to standard error.
The following options are supported:
–help : Show usage information
-l line-width : Specify desired line width (default 80)
-s : Output indented with tabs instead of spaces (default spaces)
-t tab-size : Use specified tab size (default 4)
-o : Write output to standard output instead of file (implies -w)
-w : Overwrite input files with their beautified form (default no)
The PHP Beautifier has finally got a real command line interface.
The features are:
* can be called from the command line or from a script
* accepts input and output file name, as well as additional argument (such as –add-header)
* compresses output by default
* supports multiple input files, by either specifying them on the command line or in a configuration file.
You can get the new version here: php beautifier
PHPB has a new feature! PHPB Command Line Interface (CLI) is now available.
Usage: phpb [options] inputfile…
-h, –help Display this help message.
-i, –indent=n Set indentation to n spaces. Default = 4 spaces.
-o, –output=f Output to file f. Default = standard output.
-q, –quiet Suppress informational messages.
-r, –recursive Recursively beautify all PHP files in the directory or given by -o. If -o is not used, the current working directory will be used. Note that if -o is used and recursion is selected, the output file specified with -o must be a directory or an error will occur. When recursion is selected and the input file(s) are directories, only php files (*.php) will be processed and subdirectories will be ignored. If any input file is not a php file or directory an error will occur unless recursion is not selected in which case it will simply be ignored as input and processing will continue on any other files specified on the command line or via standard input (see below).
PHP Beautifier is a tool which allows you to format your code according to a set of standards. You can configure the output style according to your own preferences, or you can use one of the many predefined styles available.
With PHPBeutifier, you can:
Format your source code with a comprehensive set of formatting options.
Configure the formatting options interactively or programmatically.
Generate a model file that stores the state of the formatting options dialog box.
Edit a model file and apply it to other source files automatically.
Process a single file or multiple files in batch mode with an operating system command or script.
Use a command line interface to process files in batch mode without interaction from the user.
As a PHP developer, you write PHP codes for hours and hours everyday for more than one project. You may need to beautify many php files, but it’s so boring to copy & paste them from your editor to the web page of PHPBeautifier. Then you have to switch back and forth between your browser and your editor. What a waste of time!
But no more! Now PHPDoc has a command line interface (CLI) which allows you to perform batch beautification right in your terminal window. This feature is available in version 0.16.3 or later.
To use this feature, simply download the latest PHPDoc package and unzip it on your local disk. You can find the executable file named phpdoc in the bin directory. Then try the following commands:
$ phpdoc –version
PHPBeautifier 0.16.3 (c) 2004-2007 Claudio Bustos Hernández firstname.lastname@example.org
$ phpdoc –help
-s, –standard=STANDARD_NAME set standard to STANDARD_NAME (PEAR,PHPCS,ZEND)
-o, –output=FILE save output to FILE