PHP Code Formatter: Re-indent PHP Inside <?php Tags
Fixes indentation, blank lines and optionally line breaks in PHP code without sending it anywhere.
Use the tool
Why this tool exists
Messy indentation hides the structure of PHP code, and minified or copy-pasted code is worse. A re-indenter gives you the block layout back quickly.
The tool reads your code with a small scanner that knows strings, comments and raw literals, so braces inside them are ignored. It then sets the indent from bracket depth and, if you ask, puts a line break after braces and semicolons. It is not PHP-CS-Fixer.
How to use it
- Paste PHP code, with or without HTML around it.
- Pick the indent and line break mode.
- Copy the result.
- Use PHP-CS-Fixer for PSR-12.
Frequently asked questions
Is this the same as PHP-CS-Fixer?
No. PHP-CS-Fixer and PHPCBF apply PSR-12 rules. This tool only re-indents and optionally breaks lines. Syntax of the test files was still accepted by php -l after breaking.
Will it change what my code does?
It only changes whitespace outside strings, comments and raw literals. Test results: the non-whitespace text was unchanged on all test files, and re-running the tool gave the same output. Review the diff anyway.
Why not wrap long lines?
Wrapping needs a full parser. This tool does not have one.
Is my input sent anywhere?
No. Everything runs in your browser and nothing is uploaded.