#123 · Programming Language Tools Developer Tool

PHP Formatter

Format PHP source with consistent indentation, brace placement, whitespace, blank-line handling, and protected string and comment content.

Developer Input

Local browser processing
spaces
Ad space

How to use this developer tool

  1. Paste PHP code.
  2. Select brace style and indent size.
  3. Choose whitespace options.
  4. Run formatting.
  5. Compare and download the result.

What this developer tool does

It performs a lightweight token-aware format pass designed to avoid modifying quoted strings and comments while normalizing code layout.

Protect strings/comments → normalize line endings → adjust braces and indentation → normalize safe whitespace → restore protected tokens.

This is a browser formatter, not PHP-CS-Fixer or PHP_CodeSniffer. Review complex heredoc, nowdoc, mixed HTML/PHP, and unusual alternative syntax manually.

Example

Input: if($active){echo "Active";}

Output: consistently spaced and indented PHP.

Tips for better output

  • Use 4 spaces unless your project standard specifies otherwise.
  • Run your official formatter before committing.
  • Keep mixed HTML/PHP templates small and test them after formatting.

FAQ

How can I format messy PHP code online?

Paste the source, select your indentation and brace style, and run the formatter.

How do I convert PHP indentation from tabs to spaces?

Choose a numeric indent size. The output uses spaces for generated indentation.

How can I format PHP without changing strings?

The formatter temporarily protects quoted strings and comments before changing surrounding whitespace.

How do I remove trailing whitespace from PHP code?

Enable Remove trailing spaces before formatting.

How can I compare PHP code before and after formatting?

Use the source and output areas together, then review the changed line count in the result summary.

Formatting options

ModulePurpose
Indent2, 4, or 8 spaces
BracesSame-line or next-line
WhitespaceOperators and trailing spaces
ProtectionStrings and comments

Browse more developer tools

Calldeveloper category hub