PHP Formatter
Runs in your browserPaste messy PHP and get it back consistently indented and wrapped, with or without the opening <?php tag.
Input
Output
How this one works
Paste PHP on the left and the formatted version appears on the right as you pause. Formatting is done by Prettier with its official PHP plugin, the most complete PHP formatter written in JavaScript, loaded into a background thread the first time the page is idle.
Pick the indent and line width your project uses, and the brace style: PER-CS (the successor to PSR-12) puts class and method braces on their own line, 1TBS keeps every brace on the same line. The PHP version decides which syntax is allowed, such as trailing commas in parameter lists (7.3+). Code without an opening <?php tag works too.
Questions
Why does it say there is a syntax error?
A formatter has to parse the code before it can reprint it, so it stops at the first thing PHP itself would reject, and shows the line and column. Common culprits are a missing semicolon or brace, or syntax newer than the PHP version selected above.
Does formatting change what my code does?
No. Only whitespace, line breaks and layout change, plus the quotes around simple strings if you pick a different quote style. Names, values and logic are reprinted exactly as they were.
Can it format PHP mixed with HTML, like WordPress templates?
Yes. The PHP blocks are formatted and the HTML between them is left as it is. Prettier doesn’t reformat inline HTML, so a template stays readable rather than being rewrapped.
Is it safe to paste private code here?
Yes. Prettier runs in a worker inside this tab, and your code is never uploaded, logged or stored.