PHP Classes

PHP Auto Style Fixer: Beautify PHP source code fixing its style

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 160 All time: 8,945 This week: 89Up
Version License PHP version Categories
phpas-php-auto-style 1.0GNU General Publi...5PHP 5, Tools, Parsers
Description 

Author

This class can beautify PHP source code fixing its style.

It can take as parameter PHP source code either in the form of a string or the name of a file to be parsed using pure PHP code.

The class can fix several types of formatting aspects of the given PHP source like:

- Remove multiple consecutive line breaks
- Remove needless spaces in statments like for, while, if, etc.
- Remove indenting
- Reformat comments
- Etc..

Picture of Max Base
  Performance   Level  
Name: Max Base <contact>
Classes: 5 packages by
Country: United States United States
Age: ???
All time rank: 2608359 in United States United States
Week rank: 91 Up11 in United States United States Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

Recommendations

What is the best PHP get dominant color from image class?
Extract and organize scanned images by dominant color

Example

<?php
include "PHPAS.php"
$AS=new AutoStyle();
///////////////////////////////////////
print $AS->loadFile("test.php") ."\n";
print
$AS->loadString("<?php\nprint 'hi';\n") ."\n";


Details

PHP AS(Auto Style), PHP Beautifier

A tool for format and beautify the style of PHP code with my style.

Purpose

We waste our time to format the code. So it will be a fantastic tool.

Anyway, I hope this tool can help you for format a PHP code easily and fast.

Story

I developed this tool for myself, not for money, not for a special company.

Although it used in some software of a company in India.

Also it used as PHP snippet formate on PHPize.online

Main purpose

  • Remove extra space after "for", "while", "if" words...
  • Ident cleaning and auto tab for {} and statements...
  • Make clean the comment text
  • ...

Demo

Left: Output, Right: Input

ScreenShot

Usage

<?php
/Include Class/
include "PHPAS.php"

/Create Class Instance with default options/
$autoStyle = new AutoStyle();

/or with optional configuratoin/
$options = [
	'identation' => '    ' // 4 spaces (default Tab)
];

$autoStyle = new AutoStyle($options);

/Format code from file/
print $AS->loadFile("test.php") ."\n";

/Format code from string/
print $AS->loadString("<?php\nprint 'hi';\n") ."\n";

Class Methods

| Method | Goal | | ------------------------- | ------------- | | setOptions($options) | Change formatter options... | | loadFile($fileName) | Auto Style, format a file and display output... | | loadString($codeString) | Auto Style, format a string code and display output... |

Input

<?php
/inline comment/
for ($v = 7;$v <= 100 / 10;$v++) {
$b = $v;
$x = [];
for ($i = 1;$i <= $v;$i++) {
$x[] = $i;
}
for ($k = 3;$k <= ((floor($v - 1) / 2) + 1);$k++) {
$r = $k;
solve($x, $v, $b, $k, $r);
}
}

Output

<?php
/inline comment/
for($v=7;$v<=100/10;$v++) {
	$b=$v;
	$x=[];
	for($i=1;$i<=$v;$i++) {
		$x[]=$i;
	}

	for($k=3;$k<=((floor($v-1)/2)+1);$k++) {
		$r=$k;
		solve($x,$v,$b,$k,$r);
	}

}

Input

<?php
/inline comment/
for ($v = 7;$v <= 100 / 10;$v++) { $b = $v; $x = []; for ($i = 1;$i <= $v;$i++) {$x[] = $i;
}
for ($k = 3;$k <= ((floor($v - 1) / 2) + 1);$k++) { $r = $k;
solve($x, $v, $b, $k, $r); } }
$str="hello world!";

Output

<?php
/inline comment/
for($v = 7;$v <= 100 / 10;$v++) {
	$b=$v;
	$x=[];
	for($i = 1;$i <= $v;$i++) {
		$x[]=$i;
	}

	for($k = 3;$k <= ((floor($v - 1) / 2) + 1);$k++) {
		$r=$k;
		solve($x, $v, $b, $k, $r);
	}
}

$str="hello world!";

Partnership and development

Please send issue or pull request if you found a bug or problem. Feel free to discuss or send pull...

License

PHPBeautifier is licensed under the GNU General Public License.


Screenshots  
  • screenshot.png
  Files folder image Files  
File Role Description
Files folder imagetests (2 files, 2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file Example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Plain text file PHPAS.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  tests  
File Role Description
Files folder imageoutput (1 file)
Files folder imagephp (1 file)
  Accessible without login Plain text file Generates.php Example Create Generates.php
  Accessible without login Plain text file Tests.php Example Example script

  Files folder image Files  /  tests  /  output  
File Role Description
  Accessible without login Plain text file 1.php Output Sample output

  Files folder image Files  /  tests  /  php  
File Role Description
  Accessible without login Plain text file 1.php Test Unit test script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:160
This week:0
All time:8,945
This week:89Up