Skip to content
Trending Tools

PHP Formatter

Format messy PHP into clean PSR-12 style — PHP 8 syntax and HTML templates included.

  • Free
  • No sign-up
  • Runs in your browser
PHP
PHP
Indent
Width
Braces
Quotes
Runs in your browser — your code is never uploaded.

What does PHP Formatter do?

PHP Formatter turns cramped, inconsistently indented PHP into clean, readable code. It uses Prettier with the official PHP plugin, so you get the same result your editor or CI pipeline would give: one statement per line, consistent spacing around operators, long calls and arrays wrapped to fit the line width, and braces placed the PSR-12 / PER Coding Style way.

It understands modern PHP — enums, match expressions, attributes, readonly and promoted constructor properties, named arguments, nullsafe ?-> and first-class callables — as well as template files where <?php … ?> and <?= … ?> blocks sit inside HTML. Only the layout changes; your code does exactly the same thing afterwards.

What you can use

A .php or .phtml file, a whole class, or just a snippet such as one function. A <?php tag is optional — code without one is treated as PHP. Files with HTML around the PHP blocks work too; the HTML itself is left as it is.

Example

Input

<?php
function greet($name,$greeting="Hello"){if(!$name){return null;}return $greeting.", ".$name."!";}
$users=array('ann','bob');foreach($users as $u){echo greet($u);}

Output

<?php
function greet($name, $greeting = 'Hello')
{
    if (!$name) {
        return null;
    }
    return $greeting . ', ' . $name . '!';
}
$users = ['ann', 'bob'];
foreach ($users as $u) {
    echo greet($u);
}

Default settings: PHP 8.3, 4 spaces, 80 columns, PSR-12 braces, single quotes.

How to use PHP Formatter

  1. Step 1

    Paste your PHP, drop a .php file on the box or press Open file.

  2. Step 2

    Pick your PHP version and style: indent, line width, brace style and quotes.

  3. Step 3

    Press Format PHP (or Ctrl/⌘ + Enter). Changing an option re-formats straight away.

  4. Step 4

    Copy the result or download it as a .php file.

Good to know

  • The defaults follow PSR-12 and its successor, the PER Coding Style: 4-space indents, and the opening brace of classes, functions and methods on its own line. Choose “Same line” for the 1TBS style many WordPress and Laravel snippets use.
  • Formatting never changes what the code does. A few rewrites are purely cosmetic: array() becomes [], and with “Single” quotes "text" becomes 'text' only when the string has no variables or escapes that need double quotes.
  • Set the PHP version to the one your server runs. Trailing commas in parameter lists are only added for PHP 8.0 and later, so older versions keep code they can still parse.
  • If you see a syntax error, the message gives the line and column — press Show in code to jump there. The formatter can’t tidy code that PHP itself couldn’t parse, such as a missing semicolon or bracket.
  • Plain HTML outside the <?php … ?> blocks is not re-indented, so templates keep their markup exactly as written.

Your privacy

Everything happens in this browser tab: what you paste is converted by JavaScript on your device and never sent to our server. Closing the tab clears it. Even so, don’t paste live passwords, API keys or customer records into any website.

All Trending Tools

Frequently asked questions

Is PHP Formatter free?

Yes. PHP Formatter is completely free, with no sign-up, no watermark and no daily limit.

Is the data I paste sent to a server?

No. Conversion runs in JavaScript inside this browser tab and nothing you paste is sent or stored. Even so, avoid pasting live passwords, API keys or private customer data into any website.

Why do I get an error?

Almost always the input isn’t quite valid: a missing comma or quote in JSON, an unclosed tag in XML, or a tab in YAML. The error message shows where parsing stopped — fix that spot, or press “Load example” to compare with input that works.

Does it work on my phone?

Yes. It works in any modern browser on Android, iPhone, tablets and computers — nothing to install.