Previous Up Next
Script use How to use PHP_Beautifier Filter architecture

Command Line use

Instructions and examples of using the command line

Claudio Bustos Jens Bierkandt

Table of Contents

Locate the script

First, you should know where the script resides. The Pear installer puts the script on the PHP binary directory or in PHP_PEAR_BIN_DIR if defined. So, in linux, the script php_beautifier is included in the path of executables (/usr/bin/php_beautifier). On Windows, a batch file called php_beautifier.bat is created as a wrapper for php_beautifier

Running the command-line in MS Windows

First, put the path where resides the php_beautifier.bat executable on PATH, and type on a console window :

c:\>php_beautifier [commandline]

Running the command-line in Linux

By default, the script is located in the path of executables, with execute permitions, so you only have to type:

$ php_beautifier [commandline]

Command line options and parameters

NOTE: Use the short options. Console_Getopt doesn't works well with long options


php_beautifier -f input_path -o output_path -c compression_type -t number -s number -l filter_def -d path -r -? input_path... output_path input_path
  • File name(s) (allowed * and ? for batch processing) or - for STDIN.

  • output_path
  • Path to a dir (with '/' at the end), to a single file (without the '/') or - for STDOUT

  • compress_type
  • Set compression. Modes can be 'gz' (default) and 'bz2'

  • filter_def
  • "FilterName (param=value , param=value...  FilterName...)"

    The name of the filter should be written in StudlyCaps. The settings are inside the parenthesis, separated by commas; the value is preceded by '='. Other Filter could be added, separated by spaces.

  • The default input/output of the tool are STDIN/STDOUT. So, don't be surprise if nothing happens when you call the tool without any options!


    Command-line options
    short option long option description
    -f --input input path
    -o --output output path
    -c --compress Compress the output ('tz','bz2')
    -t --indent_tabs Indent with tabs
    -s --indent_spaces Indent with spaces
    -l --filters Add one or more filters
    -d --directory_filters Add a filters directory.
    -r --recursive Turn on recursive mode
    -? --help Display help / usage


    Set the input pattern for beautify. * and ? are allowed for batch processing. If recursive mode ( -r) is turned on, the pattern may catch directory names. - get input from standard input


    Set the output for beautify. If the param ends in '/' and the input matches one or more files, the program try to recreate the input directory structure. If the param doesn't end in '/', the output will be one file. - set the output to standard output


    Set compression for output file(s). You can select 'gz' or 'bz2'. If output is a dir, all the files are compressed separately!


    Tabs are used as indent char. Without a param, the number of tabs for indent is 1


    Spaces are used as indent char. Without a param, the number of spaces for indent is 4


    Add one or more filters to the process. Look on Usage the definition for the command

    $ php_beautifier --filters "ArrayNested Pear(add_header=php)"


    Add a path to lookup for filters. See PHP_Beautifier::addFilterDirectory().


    Turn on the recursive search for files inside directories. On *nix, remember to quote the input_path


    Show the help / usage.


    We have this files structure. Current directory is /myprogam/


    Test beautify (for one file)

    Send the output to STDOUT

      php_beautifier index.php

    Test beautify (for multiple files)

    This match only the files inside /myprogram/ . The output is send to STDOUT

      php_beautifier *.php
      on *nix
      php_beautifier "*.php"

    This match all the files inside /myprogram/ and /myprogram/lib . The output is send to STDOUT

      php_beautifier -r "*.php"

    Define tabs or spaces to indent

    This create a new file with 2 spaces for indentation

      php_beautifier -s2 index.php index_new.php

    This create a new file with 2 tabs for indentation

      php_beautifier -t2 index.php index_new.php

    Use Filters

    Use PEAR standards

      php_beautifier -l "Pear()" index.php index_pear.php

    Use PEAR standards, add Apache license, nest arrays and list the functions and classes of file

      php_beautifier -l "Pear(add_header=apache) ArrayNested() ListClassFunction()" index.php index_new.php

    Handling multiple files

    Beautify all the files and send the output to one file

      php_beautifier -r "*.php" all_files.txt

    Beautify all files and recreate the dir structure on ./myprogram-beautified/

      php_beautifier -r "*.php" ./myprogram-beautified/
    Previous Up Next
    Script use How to use PHP_Beautifier Filter architecture

    Documentation generated on Mon, 31 May 2010 16:16:02 -0400 by phpDocumentor 1.4.3