PHP Formatter
Paste PHP, format it automatically, and copy clean output.
Output
formattedFree PHP formatter
Format PHP code online without leaving the page
Use this PHP formatter to clean messy classes, functions, arrays, copied snippets, and quick debugging code. Paste PHP on the left and copy formatted PHP from the right.
Format PHP code
Clean classes, functions, arrays, conditionals, and common PHP snippets.
Clean copied examples
Strip fences, line numbers, and paste artifacts before formatting PHP.
Quick copy output
Format PHP in one screen with no extra click to open the tool.
How this PHP formatter helps
Before and after formatting
Paste compact, copied, or hard-to-read PHP into the input pane. FormatPaste cleans common paste artifacts first, then formats the code into readable output that is easier to scan, debug, share, or copy into your editor.
Common PHP formatting use cases
Use it for quick snippets from documentation, AI chat output, Stack Overflow answers, config examples, API responses, old files, minified blocks, and code that picked up line numbers or markdown fences while being copied.
Safe paste reminder
FormatPaste is built for speed, but you should avoid pasting passwords, API keys, tokens, private keys, recovery codes, customer data, or other secrets into any online formatter. Use local tools for sensitive code.
PHP formatting example
<?php class Cart{private array $items=[];public function add(string $sku,int $qty=1):void{if($qty<1){return;}$this->items[$sku]=($this->items[$sku]??0)+$qty;}}
<?php
class Cart
{
private array $items = [];
public function add(string $sku, int $qty = 1): void
{
if ($qty < 1) {
return;
}
$this->items[$sku] = ($this->items[$sku] ?? 0) + $qty;
}
}
When to use a PHP formatter
Beautify legacy PHP code
Old PHP files often mix tabs and spaces, cram several statements on one line, or use inconsistent brace placement. Paste a class or function here to get a consistent layout before you start refactoring.
Format WordPress and Laravel snippets
Snippets from WordPress themes, plugins, Laravel controllers, and Stack Overflow answers come in every style. Formatting them gives the same spacing around operators, arguments, and arrays as the rest of your code.
Read compressed or one-line PHP
Code pasted from logs, chat messages, or debugging sessions is often squashed onto one line. Formatting expands classes, methods, and conditionals so the control flow is easy to follow.
PHP syntax errors
If the formatter returns an error, the snippet usually has a missing semicolon, an unclosed brace or string, or is missing the opening <?php tag. Fix the reported problem and format again.
More free online formatters
PHP Formatter FAQ
How do I format PHP online?
Paste PHP into the input pane and FormatPaste formats it automatically.
Does it support PHP classes and arrays?
Yes. It formats common PHP code including classes, methods, functions, arrays, and conditionals.
Can it format copied PHP snippets?
Yes. It is built for messy copied snippets and common paste artifacts.
Is this PHP formatter free?
Yes. It is free to use.
Which PHP versions are supported?
Modern PHP syntax is supported, including typed properties, return types, the null coalescing operator, arrow functions, match expressions, enums, and named arguments.
Do I need the opening <?php tag?
Include the <?php tag at the start of your snippet. Code without it is treated as plain text inside a PHP file and will not be formatted as PHP.
Can it format PHP mixed with HTML?
Partly. In templates that mix PHP with HTML, the PHP blocks are formatted but the surrounding HTML layout is left as you pasted it. For the markup itself, use the HTML formatter.
What brace style does the PHP formatter use?
Class and method braces go on their own line and control structures keep the brace on the same line, in the style of PSR-12. Indentation is two spaces.