Skip to main content
Home› Tools› PHP Formatter
🔧 Programming ✅ 100% Free ⚡ Instant

PHP Formatter

Format and beautify PHP code with PSR-12-style indentation and brace placement. Cleans up spacing, normalises indentation, and structures your PHP for readability.

Indent:
📥 Input
📤 Output
Ready — paste code and click Format · Ctrl+Enter to format
Lines: — Size: —
Load example: ▶ Function ▶ Class
📊 Stats
—
Lines
—
Size
💡 Quick Reference
PSR-12PHP style guide
4 spacesStandard indent
{Same line as statement
?>Omit closing tag
declarestrict_types=1

What is PSR-12?

PSR-12 is the PHP coding style standard maintained by the PHP-FIG (Framework Interop Group). It extends and replaces PSR-2, defining rules for indentation (4 spaces), brace placement, line length, namespace declarations, and more. Major PHP frameworks like Laravel and Symfony follow PSR-12, making it the de-facto standard for modern PHP development.

Frequently Asked Questions

PSR-12 mandates 4 spaces (not tabs) for indentation. While PHP itself accepts either, mixing them causes inconsistency across editors and diff tools. Most modern PHP projects and frameworks enforce spaces via tools like PHP-CS-Fixer or PHP CodeSniffer.
PSR-12 recommends omitting the closing ?> tag in PHP-only files. This prevents accidental whitespace or newlines after the tag from being sent as output before headers, which can cause "headers already sent" errors. Always omit it in class files, configuration files, and includes.
This formatter is optimised for PHP-only files (class files, functions, config). Mixed HTML/PHP templates have complex formatting rules that differ significantly. For mixed files, consider using a full IDE formatter like PhpStorm or VS Code with the PHP Intelephense extension.
Done!

Enjoying this tool?

Every tool here is free, forever — no signup, no paywall. If this one just saved you real time, a small tip keeps them free and ad-light.

☕ Support This Tool →

Need something built, not just formatted?

This toolbox is free. If your business needs custom software, AI integration, or a system built around this kind of tooling, that's what I do for a living.

Explore Software → Book a Consultation →

Frequently Asked Questions

Is this PHP Formatter free to use? +
Yes, completely free. No signup, no account, no payment required. Just paste your input and use it directly in your browser.
Does this tool store or send my data anywhere? +
No. Everything runs entirely in your browser using JavaScript. Your data never leaves your device or gets sent to any server.
What browsers does this tool support? +
It works in all modern browsers — Chrome, Firefox, Safari, Edge, and Opera — on both desktop and mobile.
Can I use this tool offline? +
Once the page is loaded, the tool runs locally in your browser without needing an active internet connection for most operations.
🔧
Custom Development

Need a Custom Version of This Tool?

This PHP Formatter works for most use cases — but if you need batch processing, API access, private hosting on your own domain, or a completely bespoke tool built around your workflow, I can build it.

Request Custom Build → Typical turnaround: 3–7 days