Home » Developer Tools » PHP Beautifier

PHP Beautifier

Paste messy PHP and get clean readable code with consistent indentation in seconds.

Last updated 13 November 2026

Upload a file: or paste code below.
Input0 chars
Output0 chars
Original size0 B
Result size0 B
Change0%

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.

How to Beautify PHP

  1. Paste your code: paste PHP into the input box or upload a PHP file, including files that mix HTML and PHP.
  2. Choose your indent size: pick 2 spaces or 4 spaces to match your project style.
  3. Click Beautify PHP: your formatted code appears instantly in the output box.
  4. Copy or download: copy the result or download it as a PHP file for your project.

Why Use This PHP Beautifier

What Is a PHP Beautifier

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.

Worked Example

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.

What This Tool Does and What It Does Not Do

What it does

What it does not do

PHP Beautifier or PHP Formatter

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.

Format PHP for Laravel and WordPress

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.

2 Spaces or 4 Spaces

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.

Frequently Asked Questions

Is the PHP Beautifier free to use?

Yes, it is completely free with no sign up.

Does beautifying change how my code works?

No. Beautifying only changes indentation and spacing. Your logic and values stay exactly the same.

Does it work with files that mix HTML and PHP?

Yes. HTML outside PHP blocks is kept in place, and only the PHP blocks are reformatted.

Does it change heredoc text?

No. Heredoc and nowdoc content is copied exactly, including its line breaks, so your output text cannot change.

Can I choose the indent size?

Yes. Pick 2 spaces or 4 spaces from the indent size option to match your project style.

Is my code uploaded to a server?

No. All formatting happens in your browser on your own device, so your code never leaves your computer.

Does it work with Laravel or WordPress code?

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.

Which PHP versions does it work with?

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.

Does it fix syntax errors?

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.

What happens to blank lines in my 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.

Can I format code without the <?php tag?

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.

Can I use tabs for indent?

No. The tool offers 2 spaces or 4 spaces only, with 4 spaces as the default. There is no tab option.

↑