Giter Club home page Giter Club logo

phpas's Introduction

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.

phpas's People

Contributors

basemax avatar rozhnev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

phpas's Issues

BUG: wrong function formatting

When I try to format next code:

function checkifhoused($productname, $supplier)
{
    $db = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
    $sql = "SELECT * FROM " . TBL_PRODUCTS;
    $result = mysqli_query($db, $sql);
    while ($row = $result->fetch_assoc()) {
        if ($row['supplierid'] == $supplier and $row['name'] == $productname) {
            return true;
        }
    }
    return false;
}

the formater returns

functioncheckifhoused($productname, $supplier)
 {
	$db=mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
	$sql="SELECT * FROM ".TBL_PRODUCTS;
	$result=mysqli_query($db, $sql);
	while($row=$result->fetch_assoc()) {
		if($row['supplierid']==$supplierand$row['name']==$productname) {
			returntrue;
		}

	}

	returnfalse;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.