PHP_Beautifier
Friday, March 27th, 2009PHP_Beautifier is a Pear package used to make your code beautiful, the same as PHP_CodeSniffer, PHP_Beautifier use tokenizer to token the PHP code, then modify it to satisfy your need. I use this package to make the auto generated code beautiful to read. This is an example in documentation:
// Create the instance
$oBeautifier = new PHP_Beautifier();
// Add a filter, without any parameter
$oBeautifier->addFilter('ArraySimple');
// Add another filter, with one parameter
$oBeautifier->addFilter('Pear',array('add_header'=>'php'));
// Set the indent char, number of chars to indent and newline char
$oBeautifier->setIndentChar(' ');
$oBeautifier->setIndentNumber(4);
$oBeautifier->setNewLine("\n");
// Define the input file
$oBeautifier->setInputFile(__FILE__);
// Define an output file.
$oBeautifier->setOutputFile(__FILE__.'.beautified.php');
// Process the file. DON'T FORGET TO USE IT
$oBeautifier->process();
// Show the file (echo to screen)
$oBeautifier->show();
// Save the file
$oBeautifier->save();
$oBeautifier = new PHP_Beautifier();
// Add a filter, without any parameter
$oBeautifier->addFilter('ArraySimple');
// Add another filter, with one parameter
$oBeautifier->addFilter('Pear',array('add_header'=>'php'));
// Set the indent char, number of chars to indent and newline char
$oBeautifier->setIndentChar(' ');
$oBeautifier->setIndentNumber(4);
$oBeautifier->setNewLine("\n");
// Define the input file
$oBeautifier->setInputFile(__FILE__);
// Define an output file.
$oBeautifier->setOutputFile(__FILE__.'.beautified.php');
// Process the file. DON'T FORGET TO USE IT
$oBeautifier->process();
// Show the file (echo to screen)
$oBeautifier->show();
// Save the file
$oBeautifier->save();
Author's blog: http://php.apsique.com/
I am finding a PHP-based js beautifier to make generated js code beautiful, but I didn't find any one till now.