Language
English English Vietnamese (Tiếng Việt) Vietnamese (Tiếng Việt) Chinese (简体中文) Chinese (简体中文) Portuguese (Brazil) (Português do Brasil) Portuguese (Brazil) (Português do Brasil) Spanish (Español) Spanish (Español) Indonesian (Bahasa Indonesia) Indonesian (Bahasa Indonesia)
PHP Formatter

PHP Formatter

Beautify and reformat messy PHP code with clean indentation, brace placement, and PSR-style spacing.

Beautify PHP Code Online

This PHP formatter turns cramped, minified, or inconsistently styled PHP into clean, readable code in real time — right in your browser. Paste a one-line snippet or a whole class and the beautified result appears instantly in the right-hand panel, with proper indentation, consistent brace placement, and tidy spacing.

Built on Prettier with the official @prettier/plugin-php plugin, so the output follows a clean, conventional PSR-style layout that matches how modern PHP projects are written.

Common Use Cases

Standardize Style

Apply consistent indentation, brace placement, and spacing across PHP gathered from different files or authors.

Review & Learn

Make legacy code, tutorial snippets, or generated PHP readable before you study, debug, or commit it.

Tidy Snippets

Clean up a quick paste from a forum, an issue tracker, or a chat into properly formatted code.

How to Format PHP Code

1

Paste Your Code

Type or paste PHP into the Input panel on the left, including the opening <?php tag for best results. You can also Upload a .php file, or click Sample to load an example.

2

See Instant Output

The formatted, syntax-highlighted code appears automatically in the right panel as you type. Line numbers and a live size counter make larger files easy to navigate.

3

Adjust Options

Set the indent (2, 3, 4, 8 spaces or Tab) and the print width (80, 100, or 120) to control where long lines wrap. The output re-formats immediately.

4

Copy or Download

Click Copy to grab the result, or Download to save it as a .php file. Use Edit to tweak the output by hand before exporting.

Everything runs locally. Your code is formatted entirely in the browser and is never uploaded to a server — safe for proprietary or unreleased source.

PHP Beautifier Features & Options

Formatting Options

PHP formatting is largely automatic, with two controls that adapt the output to your project. Each change re-formats the result instantly.

OptionChoicesWhat It Controls
Indent2 · 3 · 4 · 8 spaces · TabIndentation width and the character used per nesting level.
Print Width80 · 100 · 120Target line length before long statements wrap.

What Gets Formatted

Classes & Functions

Consistent indentation and clean brace placement for classes, methods, functions, and closures.

Arrays & Modern Syntax

Short array syntax, chained method calls, and modern PHP features are formatted cleanly and predictably.

Built-In Tools

Real-Time Formatting

Output updates as you type, with Prism syntax highlighting and line numbers.

Upload & Download

Load a local .php file or export the formatted result with one click.

Editable Output

Switch the result panel to CodeMirror edit mode to make manual tweaks before copying.

New to the tool? Click Sample to load a deliberately cramped class and watch it format instantly.

Frequently Asked Questions

Does formatting change how my PHP runs?

No. Beautifying only changes whitespace, indentation, and layout — it never alters the logic or behavior of your code. The formatted output runs exactly the same as the original.

Is my code sent to a server?

No. All formatting happens locally in your browser. Your code is never uploaded, logged, or stored, which makes the tool safe for proprietary and confidential source.

What formatting engine does it use?

It uses Prettier with the official @prettier/plugin-php. The output follows a clean, conventional PSR-style layout that is consistent with what modern teams use in their editors.

Do I need to include the <?php tag?

For best results, yes. Including the opening <?php tag helps the parser correctly recognize the input as PHP and format the entire snippet reliably.

Does it support modern PHP and Laravel code?

Yes. The PHP plugin handles modern language features — classes, closures, short array syntax, and chained calls — so contemporary code, including Laravel-style snippets, is formatted correctly.

Can I customize indentation and line width?

Yes. Adjust the indent size (2, 3, 4, 8 spaces or Tab) and the print width (80, 100, or 120) from the toolbar to control indentation and where long lines wrap. The output re-formats immediately so you can preview the change.

What happens if my code has a syntax error?

The formatter cannot format code it cannot parse, so it displays an error message describing the problem. Fix the reported issue and the formatted output appears as soon as the code is valid.

Indent
Input
Output
Error

Paste code on the left to format

|
Paste your PHP including the opening <?php tag so the parser reads the whole snippet.
Handles classes, functions, closures, short array syntax, and modern PHP.
Switch the indent (2, 3, 4, 8 spaces or Tab) and print width to match your project style.
Formatting runs entirely in your browser — code is never uploaded.
Want to learn more? Read documentation →
1/5
Start typing to search...
Searching...
No results found
Try searching with different keywords