PHP Beautifier
Pretty-print and indent messy or minified PHP with consistent formatting.
What is PHP Beautifier?
PHP Beautifier takes messy, minified, or inconsistently-indented PHP and reformats it with clean, predictable 2-space indentation — one statement per line, the opening brace of every block on the same line as its `function`/`if`/`for`/`class` header, and each closing brace dedented onto its own line. Under the hood it's a tolerant state machine rather than a real PHP parser: it walks the source tracking single- and double-quoted strings (including backslash escapes), `//` and `#` line comments, `/* ... */` block comments, and heredoc/nowdoc regions, so a `{`, `(`, `)`, or `;` that appears inside a string, a comment, or a heredoc body is never mistaken for real PHP structure and is left exactly as you wrote it. That makes it safe to run on PHP pulled from a minified production bundle, a copied snippet, or a sloppy diff when you need to actually read what the code is doing before editing or reviewing it.
How to Use PHP Beautifier
- Paste your PHP — minified, messy, or just inconsistently indented — into the input box.
- The formatted version appears instantly below, with consistent 2-space indentation per nesting level.
- Copy the formatted result with the copy button.
Examples
A minified function
Input: <?php function greet($name){return "Hello, ".$name;}
Output: <?php function greet($name) { return "Hello, ".$name; }
A control structure with an else branch
Input: <?php if($active){echo "on";}else{echo "off";}
Output: <?php if($active) { echo "on"; } else { echo "off"; }
Common Mistakes
- Running this on genuinely invalid PHP and expecting it to be repaired — a formatter reformats structure, it doesn't fix broken syntax or missing semicolons.
- Expecting expressions themselves to be reformatted (for example, spaces added around operators, or commas spaced in argument lists) — this tool only handles indentation and line breaks, not operator or argument normalization.
- Pasting PHP with mismatched braces and being confused by the error — check for a missing `}` at the end of a function or block, or an extra one copied in by mistake.
- Assuming beautified output is production-ready — readable formatting is for humans; you'll usually want to minify again before shipping.
- Forgetting that `<?php` opening tags, namespace blocks, and inline HTML outside `<?php ... ?>` are passed through as ordinary text rather than deeply understood.
Why Use This Tool
- Processes entirely client-side — your PHP never leaves your browser.
- String literals, comments, and heredoc/nowdoc bodies are protected from being mistaken for structural syntax.
- Keeps `for`/`foreach`/`while` headers intact instead of splitting them at every inner semicolon.
- Instant, live formatting with no submit button.