Developer tool

PHP Formatter

Reindent and normalize PHP source formatting for readability without executing the code.

How it works

What it does

The PHP Formatter takes messy or inconsistently indented PHP and returns a more readable layout. It is aimed at human review: aligning braces, normalizing indentation levels, and making control structures easier to scan. It is not a full PSR-12 auto-fixer for every edge case, and it does not rewrite your architecture.

When to use it

  • You inherited a minified or one-line dump and need to read it
  • A ticket contains a compacted snippet that is hard to review
  • You want a quick cleanup before comparing two versions side by side
  • Teaching or documenting examples where clear indentation matters

How input is processed safely

Formatting is a text transformation over tokens/structure heuristics. The service never executes the pasted PHP, never writes files to your server, and never installs packages. Invalid syntax may prevent clean formatting—in that case, fix parse errors first with the syntax checker.

Examples

  • Expand a single-line closure so nested arrays become readable
  • Normalize mixed tabs/spaces after a copy-paste from chat
  • Make a long match expression easier to audit before commit

Common mistakes

  • Expecting identical output to PhpStorm or PHP-CS-Fixer on every project rule set
  • Formatting broken syntax and assuming the tool “fixed” logic bugs
  • Submitting megabyte-sized vendor files instead of the relevant source

Readable formatting reduces review time and makes nested ternaries, attributes, and match expressions less hazardous to edit. The formatter prefers predictable indentation over creative alignment, which keeps diffs smaller when teammates reformat later with their own IDE settings.

If your organization enforces PHP-CS-Fixer or Pint rules, treat this tool as a readability aid rather than the source of truth. Run your project’s fixer locally before committing so CI style checks stay green.

Large pastes that mix HTML templates with PHP open tags can be harder to normalize cleanly. When a file is mostly Blade/Twig with sparse PHP, format the PHP blocks in isolation or use your template-aware tooling instead.

Privacy note

Formatted output may still contain secrets that were in the input. Redact credentials and tokens before pasting. Prefer local formatters for proprietary codebases when policy requires code to stay on-premises.

Run in browser

AJAX processing only. No remote PHP execution sandbox. Results are not indexed.

Parsed with nikic/php-parser or token_get_all only. Your code is never executed (no eval/include).

Safety notes

  • Submitted tool contents are not written to analytics or search logs.
  • This site never evaluates arbitrary PHP from the browser.
  • Generated configs are starting points—validate on a staging host before production.