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
- Paste PHP code beginning with
- Pick the target PHP version and indentation.
- Toggle single quotes if you prefer them.
- Copy or download the formatted file.
Frequently asked questions
Is the output PSR-12 compliant?
Why do I get a syntax error on valid code?
<?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?
@if and {{ }} are not PHP syntax. Format the controller and model code here and Blade files with a Blade-specific formatter.