PHP Code Prettifier & Tidier
Paste messy PHP code to beautify with proper indentation, brace style, and consistent formatting
Paste messy or minified PHP and get clean, properly indented code back in one click. Pick your indent size, choose a brace style, and the formatter rebuilds whitespace without touching your logic. And everything runs in your browser. Nothing gets uploaded.
How It Works
The formatter tokenizes your PHP — splitting it into keywords, operators, strings, comments, and brackets. It then walks through each token, tracking nesting depth to apply the right indentation level. Strings and comments stay untouched. What comes out is the same code with consistent spacing, proper line breaks after semicolons, and braces placed exactly where you told it to put them.
Examples
Fixing a minified controller method
You pulled a plugin file and every method is crammed onto one line.
function getUser($id){$user=User::find($id);if(!$user){return null;}return $user->toArray();}
function getUser($id)
{
$user = User::find($id);
if (!$user) {
return null;
}
return $user->toArray();
}
Cleaning up a messy class with mixed indentation
Half the file uses tabs, the other half uses 2 spaces. Some lines have no indentation at all. Classic team project.
class Cart{
private $items=[];
public function add($item){
$this->items[]=$item;
}
public function total(){$sum=0;
foreach($this->items as $i){$sum+=$i->price;}
return $sum;}
}
class Cart
{
private $items = [];
public function add($item)
{
$this->items[] = $item;
}
public function total()
{
$sum = 0;
foreach ($this->items as $i) {
$sum += $i->price;
}
return $sum;
}
}
Quick array reformatting
A config array that's been squished into one line.
$config=['db'=>'mysql','host'=>'127.0.0.1','port'=>3306,'options'=>['timeout'=>30,'retry'=>true]];
$config = [
'db' => 'mysql',
'host' => '127.0.0.1',
'port' => 3306,
'options' => [
'timeout' => 30,
'retry' => true
]
];
Who Uses This
Reformatting legacy PHP files before code review or merging into a project with PSR-12 style rules.
Making homework submissions readable after writing code in a basic text editor with no auto-indent.
Cleaning up theme or plugin files downloaded from third-party marketplaces that ship with awful formatting.
Prettifying someone else's pull request locally to actually understand what the code does.
Common Mistakes
A missing semicolon or unclosed bracket will throw off the formatter's nesting logic. The output might look oddly indented because the parser can't figure out where a block ends. Fix syntax errors first, then prettify.
If you paste raw PHP without the opening tag, the formatter may treat it as plain text. Include <?php at the top so the tool knows it's working with PHP code.
This prettifier fixes indentation and brace placement, but it won't rename variables or reorder use statements to match PSR-12. It handles the whitespace side of things. For full standard enforcement, pair it with PHP CS Fixer in your local environment.
Technical Details
- Processing: 100% client-side — your code stays in the browser
- Browser Support: Chrome, Firefox, Safari, Edge
- PHP Syntax: Supports PHP 5.x through 8.x features (enums, match, arrow functions, named args)
- Indent Options: 2 spaces, 4 spaces, or tabs
- Brace Styles: Collapsed (same line) or expanded (new line)
Frequently Asked Questions
Is this PHP formatter free?
Yes, completely free with no limits. There's no account to create, no daily cap on how many times you can format, and no watermark added to the output. Just paste and go.
Will formatting my PHP code change how it runs?
No. The prettifier only touches whitespace — indentation, line breaks, and spacing around operators. It doesn't modify variable names, logic, or string contents. Your code behaves exactly the same after formatting.
Can I format PHP files with HTML mixed in?
The tool focuses on PHP blocks inside <?php ... ?> tags. HTML outside those tags gets left alone. If your file heavily mixes PHP and HTML (like a WordPress template), you'll get the best results by formatting the PHP portions separately.
What's the difference between beautify and minify?
Beautify adds indentation and line breaks so your code is easy to read. Minify does the opposite — it strips all unnecessary whitespace to make the file as small as possible. Use beautify for development, minify when file size matters (though for PHP running server-side, minification rarely helps much).
Is my PHP code uploaded to a server?
Nope. Everything happens in your browser with JavaScript. Your code is never sent anywhere, never stored, never logged. You can disconnect from the internet and the tool keeps working — that's the proof.