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
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
Choose indentation
Select 2 or 4 spaces for each brace nesting level.
-
3
Format
The tool adjusts whitespace around `{`, `}`, `;` and `,`, then inserts line breaks and indentation.
-
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
ASCII Table Reference
Full ASCII table from 0 to 127 with decimal, hex, octal, binary, standard names and HTML numeric-reference notation, including NUL, LF and DEL.
Color Palette Generator
Generate monochromatic, analogous, complementary, triadic or tetradic color palettes from a base HEX color and export copy-ready CSS variables.
FPS Counter
Measure browser FPS with requestAnimationFrame, smoothing, min/max frame rate, warnings and an optional graph. Runs locally with no upload or API.
HTML Character Reference
Searchable list of HTML entities, their named and numeric codes, and a one-click copy for special characters and symbols.
HEX Color Picker
Pick or enter a HEX colour and get RGB, HSL, approximate CMYK, relative luminance and contrast ratios against white and black.
JSON Formatter
Paste JSON to pretty-print with 2 or 4 spaces, minify it to compact output, or run a quick syntax check before copying the result.
Tool available in other languages
- PHP-formaterare [SV]
- PHP 포매터 [KO]
- Formatador de PHP [PT]
- Formateur PHP [FR]
- PHPフォーマッター [JA]
- Formater PHP [PL]
- Công cụ định dạng PHP [VI]
- Pemformat PHP [ID]
- منسّق PHP [AR]
- Formateador PHP [ES]
- PHP-formatter [NL]
- PHP-Formatter [DE]
- เครื่องมือจัดรูปแบบ PHP [TH]
- Formatter PHP [IT]
- Форматтер PHP [RU]
- PHP Biçimlendirici [TR]
- PHP 格式化工具 [ZH]