PHP Code Formatter

Format PHP with PSR-12, K&R or Allman style and PHP 8 syntax

Completely free

Checking your access…

AllFreeTool PHP Code Formatter tidies up your PHP source indentation online for free: paste the code and you get back formatting that follows PSR-12 and other well-known style standards. It supports newer PHP 8 syntax such as constructor property promotion, enums, match expressions and property attributes, and it also handles template files that mix HTML with PHP.

Formatting only adjusts whitespace and line breaks and never changes a single character of your code: strings, comments and the verbatim text inside heredoc blocks are preserved exactly, and the HTML parts of a template are not rearranged or broken. Everything is processed locally in your browser, so business code is never uploaded to a server.

Why use PHP Code Formatter on AllFreeTool?

📐

Three Brace Styles

PSR-12 and K&R put the opening brace on the same line, while Allman puts it on a line of its own.

🧠

PHP 8 Syntax

Supports modern constructs such as enums, match, readonly properties, constructor property promotion and named arguments.

🧩

Mixed Templates

Template files that mix HTML with <?php ?> can be processed without disturbing their existing structure.

🔒

Local Processing

Your code is parsed inside the browser and never uploaded, so even company projects are safe to use.

How to use PHP Code Formatter

1

Paste PHP Code

Paste plain PHP source or a template file, or click Load Sample to try it out first.

2

Choose Style and Indent

Pick the brace style, the indent width and the maximum line width.

3

Copy or Download

Once the result looks right, copy it in one click or download it as a .php file.

Common questions

Does formatting change how the code runs?+

No. Formatting only adjusts whitespace and line breaks: string contents, comment text and heredoc bodies are preserved character for character, and the token sequence PHP parses out is exactly the same as in your original source.

Will the content inside heredoc be re-indented?+

No. The bodies of heredoc and nowdoc blocks are emitted exactly as you wrote them, and only the position of the closing marker is adjusted, which prevents the content itself from changing in any way.

Are traits, interfaces and namespaces supported?+

All of them are supported, along with use imports, namespace aliases, return type declarations and union types, and the formatter only ever touches whitespace.

Why is there no minification feature?+

Because PHP is a server-side script language, minifying the source does not reduce network transfer and only makes troubleshooting and maintenance harder, which is why this tool offers formatting only.

More Utilities tools