Created
August 1, 2022 11:52
-
-
Save motebaya/5bacab9216e6226eaa0107439aa066fc to your computer and use it in GitHub Desktop.
snippet php for format php code using php parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
https://github.com/nikic/PHP-Parser/blob/master/doc/2_Usage_of_basic_components.markdown | |
https://github.com/nikic/PHP-Parser/blob/master/doc/component/Pretty_printing.markdown | |
*/ | |
require "vendor/autoload.php"; | |
use PhpParser\ParserFactory; | |
use PhpParser\PrettyPrinter; | |
if (count($argv) > 1) { | |
$prettyPrinter = new PrettyPrinter\Standard; | |
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); | |
$p = $parser->parse(file_get_contents($argv[1])); | |
echo str_replace(" ","\t",$prettyPrinter->prettyPrint($p)); | |
} else { | |
die(" usage : prettify.php <file.php>"); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment