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!