PHP Formatter
Format PHP code in a consistent, readable style with the Prettier PHP plugin, close to the PSR-12 conventions. Paste a file that starts with <?php and get normalized spacing, braces, arrays, method chains and long argument lists wrapped to your print width. Syntax errors are reported with the parser's message, line and column, which helps PHP developers clean up legacy code before review.
Frequently asked questions
Which formatter is used?
The tool runs Prettier 3 with @prettier/plugin-php 0.26 on the server. Its output follows a style close to PSR-12: four spaces per level by default, opening braces of classes and functions on their own line and one statement per line.
Does my code need an opening <?php tag?
Yes. The plugin formats code inside PHP tags. Anything outside them is treated as inline HTML and kept as it is, so a snippet without <?php comes back unchanged.
Which PHP versions are supported?
Modern PHP 8 syntax is understood, including attributes, enums, match expressions, arrow functions, named arguments, constructor property promotion and readonly classes. Older PHP 5 and 7 code formats as well.
Will the formatter change what my code does?
No. It only changes layout. A few purely cosmetic rewrites can happen, for example long array() syntax may become the equivalent short [] syntax, but the behavior of the code stays the same.
What happens with a syntax error?
Formatting stops and the tool shows the parser's message with the line and column, for example a missing closing parenthesis. Fix that spot and format again.
Can I use tabs or two spaces?
Yes. Choose 2 or 4 spaces, or enable tabs. The print width from 40 to 200 characters, 80 by default, controls when calls, arrays and conditions wrap.
Are comments and docblocks kept?
Yes. Line comments, block comments and PHPDoc blocks stay in place next to the code they describe. Their text is not reflowed.
Can it format templates that mix HTML and PHP?
It formats the PHP blocks inside such templates and keeps the HTML between them untouched. For heavy template files the result may still need manual touch ups.
How much code can I format at once?
Up to 1 MB of code per request, and formatting stops after 10 seconds. That covers even very large single files.
Is my code kept on the server?
No. The code is formatted in memory and returned to you immediately. It is not saved and only request sizes are logged.