Home » Developer Tools » PHP Beautifier
Paste messy PHP and get clean readable code with consistent indentation in seconds.
Last updated 13 November 2026
Your code never leaves your browser. Everything runs locally on your device.
This tool only formats code. It does not run, compile or execute it, so always review the formatted output before you use it in a project.
Messy PHP is hard to read, hard to review, and easy to break. The PHP Beautifier reformats your code with consistent indentation, including files that mix HTML and PHP blocks.
Heredoc and nowdoc content is never reindented, because changing it would change your output text, and strings are left untouched. Everything runs in your browser, so your code is never uploaded to a server.
A PHP beautifier is a tool that takes messy PHP code and rewrites it with clean consistent indentation and spacing. It puts each statement on its own line, lines up opening and closing braces, and adds spaces around operators, so the code is easy to read and review. It changes how the code looks, never how it works. Your logic, values, and strings stay exactly the same. If you work with markup or styles too, the HTML Beautifier and the CSS Beautifier format those files the same way, in your browser and free.
Here is the sample code from the Load Sample button, before and after formatting, at the default 4 space indent.
Input, 147 characters:
<?php function greet($name){$items=[1,2,3];if($items){foreach($items as $item){echo $item;}}else{echo "none";}return $items;} echo greet("Ada"); ?>
Output, 225 characters:
<?php
function greet($name) {
$items = [1, 2, 3];
if ($items) {
foreach ($items as $item) {
echo $item;
}
} else {
echo "none";
}
return $items;
}
echo greet("Ada");
?>
The output is 225 characters, up from 147. That is 78 characters added, and 78 divided by 147 is 0.5306, so the file is about 53 percent larger. Beautifying adds bytes because indentation and line breaks take space, and that is normal. A short line shows the same thing: the 26 character input <?php echo "hi";$x=1+2; ?> formats to 32 characters, 6 more, or about 23 percent larger. Switch the indent to 2 spaces and the same sample comes out at 197 characters instead of 225.
<?= and short <? tags, plus endif, endfor, endforeach, endwhile, endswitch, else, elseif, catch, and finally.<?php tag and the tool only trims each line, it does not beautify it. Add the opening tag first.Beautifier and formatter mean the same thing here. Some people search for a PHP beautifier and some for a PHP formatter, but both want the same result: messy code turned into clean readable code. This page covers both, so there is no need for a second page. When your code is readable again and ready to ship smaller, the PHP Minifier shrinks the same code for publishing.
Laravel controllers, WordPress plugin files, and plain PHP scripts are all PHP files, so the same formatter works on each of them. Paste the file content or upload the PHP file, pick the indent your project uses, and copy the result back into your editor. Files that mix HTML and PHP work too: the HTML stays where it is and only the PHP blocks are formatted. For a whole project, use a command line tool such as PHP-CS-Fixer, which formats every file at once. This page is for one file at a time, in your browser, with nothing to install.
Pick the indent size that matches your project. The tool offers 2 spaces or 4 spaces, with 4 spaces as the default. The same sample code comes out at 197 characters with 2 spaces and 225 characters with 4 spaces, because deeper nesting adds more spaces per line. If your team uses 4 spaces, keep the default. If your project uses 2 spaces, switch before you copy the result. There is no tab option, so projects that use tabs should convert tabs to spaces first.
Yes, it is completely free with no sign up.
No. Beautifying only changes indentation and spacing. Your logic and values stay exactly the same.
Yes. HTML outside PHP blocks is kept in place, and only the PHP blocks are reformatted.
No. Heredoc and nowdoc content is copied exactly, including its line breaks, so your output text cannot change.
Yes. Pick 2 spaces or 4 spaces from the indent size option to match your project style.
No. All formatting happens in your browser on your own device, so your code never leaves your computer.
Yes. Laravel controllers and WordPress plugin files are plain PHP files, so paste the file content or upload the PHP file and format it the same way. Files that mix HTML and PHP work too.
Any version. The tool only reindents text and never runs your code, so the PHP version does not matter for formatting. It does not check version specific syntax, so review the output in your editor before you use it.
No. The tool does not check syntax and does not report errors. A missing semicolon or an unbalanced bracket stays in the output, so fix errors in your editor first and then format the code.
Blank lines are removed. The formatter drops empty lines as it reindents, so add spacing back in your editor if you want blank lines between blocks.
No. Code pasted without the opening PHP tag is only trimmed line by line, not beautified. Add the opening tag at the start of your code, then format it.
No. The tool offers 2 spaces or 4 spaces only, with 4 spaces as the default. There is no tab option.
When your PHP is readable again and ready to ship smaller, try the PHP minifier to shrink it.