PHP Formatter & Beautifier

Format PHP source with the Prettier PHP plugin. Braces, indentation, arrays and method chains are laid out in a consistent, PSR-12-like style.

Loading tool…

About the PHP Formatter

This formatter runs @prettier/plugin-php, the official Prettier plugin for PHP, which parses code with php-parser and prints it using Prettier's layout algorithm. Classes and methods get braces on their own lines as in PSR-12, control structures keep the opening brace on the same line, long argument lists and method chains ($query->where()->orderBy()) break one call per line, and short arrays are used consistently.

The PHP version setting tells the printer which syntax is safe to emit — for example trailing commas in parameter lists are only valid from PHP 8.0. It does not upgrade your code. Single quotes prefers '…' for strings that contain no escapes or variables; double-quoted strings with interpolation such as "Hello {$name}" are left as they are.

The input must be a PHP file, starting with <?php. Files mixing HTML and PHP are supported for simple templates, but heavy interleaving can produce awkward output; Blade and Twig templates are not PHP and will not parse. Syntax errors are reported with the line number. The code is formatted in your browser and never uploaded.

How to use it

  1. Paste PHP code beginning with
  2. Pick the target PHP version and indentation.
  3. Toggle single quotes if you prefer them.
  4. Copy or download the formatted file.

Frequently asked questions

Is the output PSR-12 compliant?
It is close to PSR-12 for braces, indentation and spacing, but not identical in every case. For strict PSR-12 enforcement use PHP_CodeSniffer or PHP-CS-Fixer in CI.
Why do I get a syntax error on valid code?
Check that the snippet starts with <?php. Without it, the parser treats everything as inline HTML. Snippets that are only part of a class body also need to be wrapped in a class.
Does it work with Laravel Blade templates?
No. Blade directives such as @if and {{ }} are not PHP syntax. Format the controller and model code here and Blade files with a Blade-specific formatter.

Related tools