Format PHP code online with smart HTML+PHP mixed mode support. Fixes -> object operators, handles pure PHP and embedded templates. 100% browser-based.
The PHP Formatter is a browser-based tool with a multi-stage formatting pipeline that handles both pure PHP files and mixed HTML+PHP templates. For pure PHP, it formats the code body as JavaScript through js-beautify with K&R brace style, then applies a PHP-specific post-processor that restores object operators (`->`) and string concatenation dots that js-beautify incorrectly reformats. For mixed HTML+PHP files, it pre-formats complex PHP blocks in-place, stashes all PHP tokens, formats the HTML skeleton with Prettier-like indentation, then restores the stashed PHP blocks at their correct indentation level. All processing runs in a Web Worker; your code never leaves the browser.
QDoes this support PHP 8 syntax?
Yes — named arguments, match expressions, fibers (PHP 8.1), nullsafe operator (?->), union types, and attributes (#[Attribute]) are all preserved, as the formatter treats PHP body code as JavaScript-like syntax for indentation purposes.
QHow does it handle mixed HTML+PHP files?
The formatter stashes PHP blocks, formats the HTML skeleton to produce correct indentation, then restores the PHP blocks at their contextually correct indent level — producing a readable mixed-mode file.
QIs my code sent to a server?
No. All formatting runs locally in a Web Worker inside your browser. Nothing is transmitted to any server.