PHP Formatter

Paste a short PHP snippet to add line breaks around braces and semicolons and indent nested braces with 2 or 4 spaces. This is a lightweight text reflow, not a syntax-aware formatter. It can help make simple, compact code easier to scan, but you must review and test the result before using it.

How to reflow a PHP snippet

  1. 1

    Paste the snippet

    Enter PHP text, with or without the opening `<?php` tag. Avoid confidential code: the text is sent to our server for processing.

  2. 2

    Choose indentation

    Select 2 or 4 spaces for each brace nesting level.

  3. 3

    Format

    The tool adjusts whitespace around `{`, `}`, `;` and `,`, then inserts line breaks and indentation.

  4. 4

    Review and copy

    Check literals, comments, heredocs, control structures and syntax, then copy the result if it is still correct.

What this formatter changes

  • It removes surrounding whitespace from {, } and ;, and changes comma spacing to , .
  • It starts a new line at braces and after every semicolon.
  • It indents brace nesting with the selected 2 or 4 spaces and removes repeated blank lines from the result.

Important limitations

The tool uses regular expressions and a character-by-character brace counter; it does not tokenize or parse PHP. It does not validate any PHP version, check syntax, understand PSR-12/PER Coding Style, or apply project rules.

The first whitespace pass runs across the entire input. It may therefore alter spaces or line breaks inside quoted strings, comments, heredocs and nowdocs. Comment contents are not recognised, and semicolons or braces in them can be treated as code. Even escaped quotes with complex backslash sequences may confuse the simple quote tracking. Use it only for uncomplicated snippets and compare the output carefully with the original.

For syntax-aware project formatting, use a maintained formatter such as PHP CS Fixer or Laravel Pint with your project configuration. Run PHP’s syntax checker and your tests after any formatting change.

Processing and privacy

Formatting runs in the component on our server; the pasted source is transmitted when the tool processes it. In the two-step flow, the browser also keeps the input temporarily in sessionStorage so it can move between steps. The tool does not execute the pasted PHP, but it is not suitable for secrets or confidential source code.

Frequently Asked Questions

No. It applies only a few whitespace and line-break rules. It does not parse PHP or implement PSR-12/PER Coding Style.

No. The code is sent to the server for formatting. The two-step flow also uses browser sessionStorage to carry the input between steps.

Not guaranteed. The initial whitespace replacements affect the whole input, and comments, heredocs and nowdocs are not parsed as PHP constructs. Always compare the result with the original.

No. It neither checks syntax nor executes the snippet. Validate the result with PHP and run the relevant tests before using it.

Related Tools

Tool available in other languages