PHP Formatter and Beautifier

Paste messy PHP and get it back clean and easy to read. The formatter follows the common PSR-12 style and runs in your browser, so your code stays on your device.

Indent
Line width

Format uses Prettier with the PHP plugin. Options apply to Format.

Result

What the PHP formatter does

The formatter reads your PHP and rewrites it in a clean, consistent style. It fixes indentation, tidies spacing around operators and brackets, puts braces where PSR-12 expects them, and wraps long lines to fit your width. It changes only the layout, never what the script does.

Why use our PHP formatter

  • ·Free. No signup, no paywall, no limits.
  • ·Runs in your browser. Formatting happens locally, so your code is never uploaded.
  • ·PSR-12 style. Output follows the coding standard most PHP teams already use.
  • ·Your settings. Choose the indent, quote style, and line width before you format.
  • ·Syntax highlighting. The editor colours keywords and strings, and lets you collapse and expand blocks.

How the PHP formatter cleans up code

Format

Rewrites your PHP with Prettier and its PHP plugin. It fixes indentation, spacing, and line breaks so the code follows one clean, consistent style.

Beforefunction greet($n){return 'Hi '.$n;}Afterfunction greet($n) { return 'Hi ' . $n; }

Indentation

Choose 2 or 4 spaces per level. PHP code most often uses 4 spaces, following the PSR-12 coding standard, but you can pick whichever your project prefers.

BeforeMixed or no indentationAfterEven, consistent indentation

Quotes and width

Prefer single quotes for strings, and set the line width the formatter wraps at. Long calls and arrays break across lines to stay within the width you pick.

BeforeLong line, mixed quotesAfterWrapped, consistent quotes

When to format PHP

A formatter helps whenever you have PHP that is hard to read or does not match your project's style. These are the cases that come up most:

  • ·Cleaning up pasted code. Fix the layout of PHP copied from a forum, a tutorial, or a chat.
  • ·Matching a team style. Reformat old code to the PSR-12 layout the rest of the project uses.
  • ·Reading dense code. Expand minified or tightly packed PHP so you can follow what it does.
  • ·Quick formatting without a setup. Format a snippet when you do not have PHP or a formatter installed.

Where to read more about PHP

When you need to check how a function works or look up a piece of syntax, the PHP Manual is the reference to keep open. It covers the whole language and every built-in function.

The layout this tool produces comes from PSR-12, the coding standard most PHP teams agree on, applied by the Prettier PHP plugin. Read either one to see the rules behind the output.

If you work across languages, these formatters run the same way, right in your browser:

Frequently asked questions

What is a PHP formatter?
A PHP formatter takes PHP source code and rewrites it in one clean, consistent style, with correct indentation, spacing, and line breaks. This tool uses Prettier with its PHP plugin, which follows the widely used PSR-12 layout, so your files look consistent and match what most PHP teams expect.
How do I format PHP code?
Paste your PHP into the input box and click Format. The clean version appears below. Click the copy button to copy it, or download it as a .php file. You can set the indent, quote style, and line width before formatting.
Do I need to include the <?php tag?
Adding the opening <?php tag is best, since that is how real PHP files start and how the formatter reads the code most reliably. The editor will still highlight a plain snippet, but include the tag when you can so the result is correct.
Does this follow PSR-12?
Yes, closely. The PHP plugin for Prettier lays code out along the lines of PSR-12, the common PHP coding standard, with 4-space indentation and braces on their own line for functions and classes. You can still change the indent and line width to fit your project.
Does formatting change how my PHP program works?
No. The formatter only changes whitespace, quotes, and line breaks. Your variables, functions, and logic stay the same, so the script runs exactly as before.
Is my PHP code kept private?
Yes. The formatter runs entirely in your browser. Your code is never uploaded to a server or saved anywhere, so you can safely paste in code from a private project. Once the page has loaded you can even use it offline.