PHP Formatter
Format and beautify PHP code with consistent indentation, entirely in your browser.
Paste your PHP code below - this tool reformats it with consistent, readable indentation.
More Programming Language Tools
View all 23For array/data conversion between PHP and JSON, see the PHP Array to JSON and JSON to PHP Array tools.
What Does This Tool Do?
It re-indents PHP source code with consistent brace placement and spacing, making inconsistently-formatted or minified PHP readable again.
Why Use This Tool?
Code merged from multiple sources, or copy-pasted from documentation with inconsistent formatting, is much easier to review and debug once consistently indented.
How to Use It
- Paste your PHP code (with or without the opening
<?phptag). - Click Format.
- Copy the reformatted code.
Limitations
This handles common PHP syntax formatting - it does not execute your code, so it can only catch structural/syntax issues that prevent parsing, not runtime logic errors.
Example
<?php
function discount($price,$percent){if($percent<=0){return $price;}return round($price*(1-$percent/100),2);}
becomes:
<?php
function discount($price,$percent) {
if($percent<=0) {
return $price;
}
return round($price*(1-$percent/100),2);
}
The formatter fixes line breaks and indentation. Spacing inside a line, such as around operators, is left as written - project tools like Laravel Pint normalise that too.
PHP Style Standards
Most modern PHP follows PER Coding Style (the successor to PSR-12): 4-space indentation, opening braces for classes and functions on their own line, and one space after control keywords such as if and foreach.
For Projects: Automate It
- Laravel Pint -
./vendor/bin/pint, zero configuration for Laravel projects. - PHP-CS-Fixer - highly configurable, works with any framework.
- PHP_CodeSniffer - reports and fixes style violations in CI.
Run one of these on every commit so formatting never appears in code review. Use this page for quick fixes to snippets from documentation, tickets or chats.
Related: JSON to PHP Array, PHP password hash generator and the Code Beautifier.
Frequently Asked Questions
Explore More Tools
Keep going with related categories and our most used tools.