PHP Formatter & Beautifier
Clean up PHP classes, functions, and control structures with safe in-browser formatting.
- Runs in your browser
- Free, no signup
PHP formatting runs client-side in JavaScript without executing your PHP code — your scripts are never uploaded or executed.
Maintaining consistent coding standards is vital when working with PHP applications, WordPress plugins, and Laravel frameworks. ToolDuck PHP Formatter beautifies messy PHP files into clean, PSR-12 styled code.
It structures classes, methods, namespaces, use declarations, and control structures with standard 4-space indentation, while preserving comments and string literals.
How to use this tool
- Paste your PHP code (including the <?php opening tag) into the editor or click "Load Sample".
- Select your preferred indentation (4 spaces standard or 2 spaces) in the options bar.
- Click "Format / Beautify" to structure code, or "Minify" to collapse whitespace.
- Copy the formatted PHP output or click "Download .php" to save your file.
PSR-12 Style Alignment and Structure
The formatter applies PSR-12 recommendations: 4-space indentation, braces on new lines for classes and functions, and clear separation between control statements.
Single and double-quoted strings, line comments (//, #), and docblocks (/** */) are preserved intact.
Frequently asked questions
Is my PHP code executed on the server?
Never. ToolDuck parses and formats PHP strictly on the client side using JavaScript. Your PHP code is never executed or uploaded.
Does it support PHP 8 syntax?
Yes. Typed properties, attributes, union types, match expressions, and named arguments are formatted cleanly.