PHP Formatter
Re-indent PHP code consistently based on brace depth. It runs entirely on your device — nothing is uploaded.
Example
Paste PHP to normalise its indentation. This is a brace-depth re-indenter, not a full PHP-aware reformatter.
How it works
This formatter normalises indentation using brace and bracket depth. It's a language-agnostic re-indenter — it tidies structure rather than rewriting style.
Good to know
The PHP Formatter cleans up messy PHP indentation by re-aligning each line according to how deeply it sits inside braces { } and brackets [ ]. It is a structural re-indenter rather than a full PHP-aware beautifier, so it fixes inconsistent or broken indentation without trying to enforce a particular coding standard like PSR-12, reorder statements, or touch spacing inside expressions. It is handy for developers who have pasted code from a chat, a forum answer, an email, or a diff and ended up with collapsed or jumbled indentation.
Reach for it when you want a quick visual tidy-up rather than a strict lint pass: normalizing a snippet before sharing it, making a tangled legacy function readable enough to understand, or cleaning indentation that got flattened during a copy-paste. Because it works on bracket depth alone, it handles any brace-and-bracket structure consistently, which is also why the same engine can re-indent related C-style languages.
To read the result, scan the left edge: every increase in indentation should line up with an opening brace or bracket, and every dedent with a matching close. If a block looks under- or over-indented after formatting, that usually points to an unbalanced brace in your source — the formatter mirrors your delimiters faithfully, so a misalignment is often a signal that something is genuinely mismatched.
One caveat to keep in mind: because the tool tracks delimiter depth and not PHP syntax, braces or brackets that appear inside strings, comments, or heredocs can skew the indent count. If a block of code suddenly shifts after formatting, check nearby string literals for stray { or } characters, and run the output through your IDE or a syntax check before committing it to production.
Frequently asked questions
Is my data uploaded anywhere?
No — everything runs in your browser. Your code never leaves your device, so it's safe for private work and runs offline once loaded.
Is this tool free?
Yes, completely free with no sign-up and no limits.
People also ask
Does the PHP Formatter follow PSR-12 or PSR-2 coding standards?
No. It re-indents lines based on brace and bracket depth only and does not enforce style rules such as PSR-12 or PSR-2. For full standards compliance you would use a dedicated tool like PHP-CS-Fixer or PHP_CodeSniffer.
Will it change my code logic or rewrite statements?
No. It only adjusts leading whitespace (indentation) on each line. It does not move, merge, split, or rewrite any statements, so the behavior of your code stays the same.
Can it fix broken or unbalanced braces in my PHP?
It will not add or remove braces, but uneven indentation in the output often reveals where a brace is unmatched, making it easier to spot the problem yourself.
Does it use tabs or spaces for indentation?
It applies a consistent indent unit per brace level when re-aligning the code. It standardizes indentation across the snippet rather than mixing tabs and spaces inconsistently.
Can I use it on code other than PHP?
Yes. Because it works on generic brace and bracket nesting, it can re-indent other C-style languages with similar delimiter structure, though it is labeled for PHP.
Why did a string with a curly brace get indented oddly?
The formatter counts braces and brackets without parsing PHP syntax, so a { or } inside a string, comment, or heredoc can be miscounted as a nesting change and shift the indentation.
Is the PHP Formatter safe to use with private or proprietary code?
Yes. All processing happens locally in your browser and the code is never uploaded, so it can be used on confidential or internal codebases, and it works offline once the page has loaded.
Related tools