Tools

Home
JSON FormatterSQL FormatterJS ValidatorMinify CSS
Merge PDFCompress PDFImage to PDF
JPG to PNGPNG to WebPCrop Image

PHP Code Prettifier & Tidier

Paste messy PHP code to beautify with proper indentation, brace style, and consistent formatting

Your files never leave your browser
Input0 chars, 0 lines
Output0 chars, 0 lines
Ready·

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

Paste PHP Code
→
Parse & Reformat
→
Clean Output

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.

INPUT
function getUser($id){$user=User::find($id);if(!$user){return null;}return $user->toArray();}
OUTPUT
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.

INPUT
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;} }
OUTPUT
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.

INPUT
$config=['db'=>'mysql','host'=>'127.0.0.1','port'=>3306,'options'=>['timeout'=>30,'retry'=>true]];
OUTPUT
$config = [ 'db' => 'mysql', 'host' => '127.0.0.1', 'port' => 3306, 'options' => [ 'timeout' => 30, 'retry' => true ] ];

Who Uses This

👨‍💻 Backend Developers

Reformatting legacy PHP files before code review or merging into a project with PSR-12 style rules.

🎓 Students

Making homework submissions readable after writing code in a basic text editor with no auto-indent.

🔧 WordPress Developers

Cleaning up theme or plugin files downloaded from third-party marketplaces that ship with awful formatting.

👀 Code Reviewers

Prettifying someone else's pull request locally to actually understand what the code does.

Common Mistakes

Pasting code with syntax errors

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.

Forgetting the <?php opening tag

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.

Expecting PSR-12 compliance from one click

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

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.

Share: