PHP Code Formatter & Beautifier
Format PHP code with PSR-12 compliant style — all in your browser, nothing sent to any server
Formatted PHP will appear here.
A WordPress plugin file with 400 lines of PHP — mixed HTML and PHP blocks, inconsistent brace placement, and tabs-vs-spaces chaos. Before you can understand the plugin’s hook registration and filter logic, you need consistent formatting that reveals the code structure.
What Is a PHP Formatter?
A PHP formatter takes PHP source code and restructures it according to PSR-12 (the PHP Standards Recommendation for coding style). It normalizes indentation, brace placement, spacing around operators and control structures, and the organization of use declarations. Whether you’re working with Laravel, Symfony, WordPress, or plain PHP scripts, a formatter brings the code to a consistent, readable standard.
This tool supports:
- 4-space indentation — the PSR-12 standard
- PSR-12 brace placement — opening braces on the next line for classes and methods, same line for control structures
- Namespace and use declarations — properly grouped and spaced
- Operator spacing — consistent spaces around
=,=>,.,??,?:
PSR-12 Key Rules
PSR-12 is the current PHP coding style standard, extending PSR-2:
- 4 spaces for indentation — never tabs
- Opening brace on the next line for class and method declarations
- Opening brace on the same line for
if,else,for,foreach,while,switch,try/catch - One blank line after namespace declaration and after the
useblock - Visibility must be declared on all methods and properties (
public,protected,private) - No closing
?>tag in files containing only PHP — prevents accidental whitespace output - Line length limit of 120 characters — soft limit, with hard limit at discretion
Common Use Cases
WordPress development: WordPress codebases often mix WordPress’s own coding standards with PSR-12. Format to your chosen standard before submitting pull requests.
Laravel/Symfony projects: Modern PHP frameworks follow PSR-12 strictly. Format code before commits to pass CI style checks.
Legacy PHP modernization: Older PHP 5.x codebases often have inconsistent formatting. Reformatting is the first step toward modernizing legacy code.
Code review: Consistent formatting eliminates style-only review comments, letting reviewers focus on logic, security, and architecture.
Frequently Asked Questions
Does this handle PHP 8 features like named arguments?
Yes. PHP 8+ features including named arguments (array_slice(array: $arr, length: 3)), union types (int|string), match expressions, attributes (#[Route("/api")]), and constructor property promotion are formatted correctly.
Can it format mixed PHP and HTML?
The formatter handles PHP code blocks. Files mixing PHP and HTML (<?php ... ?> interleaved with HTML) are partially supported — the PHP portions are formatted while HTML content is preserved.
Does it handle arrow functions?
Yes. PHP 7.4+ arrow functions (fn($x) => $x * 2) are formatted with proper spacing around the => operator.
Is my PHP code sent to a server? No. All formatting runs entirely in your browser using JavaScript. No code is transmitted anywhere. Your source code never leaves your device.