A PHP formatter restructures PHP code with consistent K&R brace style, proper keyword spacing, and clean indentation following PSR-12 conventions. Whether you are cleaning up legacy PHP 5 code or reformatting dense PHP 8 classes before a code review, this tool handles classes, functions, control flow, and PHP tags.
Formatted PHP will appear here...
Example Snippets
How to Use the PHP Formatter
PHP code written quickly, auto-generated by frameworks, or inherited from legacy projects is often poorly formatted — inconsistent indentation, missing blank lines between methods, and no spacing around operators. A PHP formatter applies PSR-12-aligned K&R brace style and consistent indentation automatically, making code readable and review-ready in seconds.
Step 1: Paste Your PHP Code
Copy your PHP code — whether a full class file, a function block, or a snippet — and paste it into the input area. The formatter handles <?php opening tags, class definitions, functions, control flow (if/for/foreach/while), try/catch blocks, and array syntax.
Step 2: Choose Indentation
Select 2 spaces, 4 spaces (default, matching PSR-12), or tabs. Click Format PHP to apply formatting. For a quick size reduction, click Minify to collapse all whitespace and strip comments.
Step 3: Copy or Download
The formatted PHP appears on the right with syntax highlighting. Click Copy to place it on your clipboard, or Download to save it as a .php file.
PHP Formatting Conventions (PSR-12)
The PHP-FIG PSR-12 standard specifies: opening braces on the same line as declarations (K&R style), 4-space indentation, one blank line between method definitions, spaces after control flow keywords (if, for, foreach, while), and no space before semicolons. Following these conventions makes your code compatible with tools like PHP_CodeSniffer and PHPStan.
FAQ
Is the PHP formatter free?
Yes, completely free with no signup required. Format unlimited PHP code in your browser.
Is my PHP code safe?
Yes. All formatting runs locally in your browser. Your PHP code is never sent to any server.
What PHP version does the formatter support?
The formatter handles PHP 5, 7, and 8 syntax patterns including short array syntax, arrow functions, null coalescing operators, and named arguments.
What brace style does the formatter use?
The formatter uses K&R (Kernighan & Ritchie) style — opening braces on the same line as the declaration. This matches PHP-FIG PSR-2 and PSR-12 coding standards.
Can I format minified PHP?
Yes. Paste any PHP code — whether a single long line or poorly indented — and the formatter will restructure it with consistent K&R brace style and indentation.
Does the formatter handle PHP tags?
Yes. The formatter properly handles <?php and ?> tags, keeping them on their own lines and preserving the PHP opening tag structure.