Skip to content

PHP Formatter

Runs in your browser

Paste messy PHP and get it back consistently indented and wrapped, with or without the opening <?php tag.

Options

Input

Output

Loading formatter…

How this one works

Paste PHP on the left and the formatted version appears on the right as you pause. Formatting is done by Prettier with its official PHP plugin, the most complete PHP formatter written in JavaScript, loaded into a background thread the first time the page is idle.

Pick the indent and line width your project uses, and the brace style: PER-CS (the successor to PSR-12) puts class and method braces on their own line, 1TBS keeps every brace on the same line. The PHP version decides which syntax is allowed, such as trailing commas in parameter lists (7.3+). Code without an opening <?php tag works too.

Questions

Why does it say there is a syntax error?

A formatter has to parse the code before it can reprint it, so it stops at the first thing PHP itself would reject, and shows the line and column. Common culprits are a missing semicolon or brace, or syntax newer than the PHP version selected above.

Does formatting change what my code does?

No. Only whitespace, line breaks and layout change, plus the quotes around simple strings if you pick a different quote style. Names, values and logic are reprinted exactly as they were.

Can it format PHP mixed with HTML, like WordPress templates?

Yes. The PHP blocks are formatted and the HTML between them is left as it is. Prettier doesn’t reformat inline HTML, so a template stays readable rather than being rewrapped.

Is it safe to paste private code here?

Yes. Prettier runs in a worker inside this tab, and your code is never uploaded, logged or stored.

Keyboard shortcuts

Global

  • Show this shortcuts dialogShift?
  • Toggle light / dark themeCtrlShiftL
  • Close dialogsEsc

Formatter & Validator

  • Format JSONCtrlEnter
  • Minify JSONCtrlShiftM
  • Copy outputCtrlShiftC
  • Download output as .jsonCtrlShiftS
  • Clear input and outputCtrlShiftX

Tree Viewer

  • Focus the search box/
  • Expand all nodesCtrlShiftE
  • Collapse all nodesCtrlShiftR

Diff

  • Swap document A and BCtrlShiftS

Time & date tools

  • Use the current time (Epoch Converter)CtrlEnter
  • Copy the main resultCtrlShiftC
  • Clear the inputCtrlShiftX

PHP Unserialize & Serialize

  • Convert an input over 2 MBCtrlEnter
  • Copy outputCtrlShiftC
  • Download outputCtrlShiftS
  • Clear input and outputCtrlShiftX

Keys & IDs

  • Generate a new token or UUID batchCtrlEnter
  • Copy the resultCtrlShiftC

JSON tools

JSON FormatterPretty-print or minify
JSON ValidatorCheck strict JSON validity
JSON Tree ViewerBrowse JSON as a tree
JSON DiffCompare two documents
JSON Path FinderExplore JSONPath expressions
JSON → CSVFlatten JSON into rows
CSV → JSONTurn rows back into objects
PHP UnserializeSerialized PHP to JSON
PHP SerializeJSON to serialized PHP

JWT tools

JWT DecoderRead header, payload, claims
JWT VerifierCheck an HMAC signature
JWT Expiry Checkeriat, nbf and exp in local time
JWT GeneratorBuild a signed test token
Base64URL EncoderEncode or decode a segment

Time & date tools

Epoch ConverterTimestamps to real dates
Cron Expression ExplainerCron in plain English
Time Zone ConverterOne moment, many cities
Duration CalculatorDate maths and durations

Keys & IDs

Password GeneratorSecure random secrets
UUID Generatorv1, v4, v5 or v7 UUIDs

Code formatters

SQL FormatterBeautify or minify SQL
HTML FormatterBeautify or minify HTML
CSS FormatterBeautify or minify CSS
JavaScript FormatterBeautify or minify JS
PHP FormatterBeautify PHP code
Markdown to HTMLConvert with a live preview

Pages

JSON toolsFormat, validate, compare and convert JSON.
JWT toolsDecode, verify and generate JSON Web Tokens.
Time & date toolsConvert timestamps, read cron, compare zones.
Keys & IDsGenerate secure tokens, passwords and UUIDs.
Code formattersFormat SQL, HTML, CSS, JavaScript and PHP code.
HomePopular tools and categories
All categoriesBrowse tools by category
AboutWhat ToolJar is and why
PrivacyWhat is and is not collected

Theme

Switch to light theme
Switch to dark theme