Skip to content
UniKit

PHP formatter

Beautify PHP in the browser: pick 2 / 4 spaces or tabs, brace placement and multi-line arrays, minify by stripping comments and whitespace, and get line/column hints for unbalanced brackets, quotes, comments or heredocs.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Opening brace
Result

Paste some PHP first

What this tool does

  • Beautify a wall of single-line PHP you inherited: choose 2 or 4 spaces or tabs, and put the opening brace on the next line or keep it on the same line, before trying to read the logic.
  • Tame long arrays and argument lists: enabling "expand arrays and arguments" puts each element on its own line, which also makes diffs easier to review.
  • Minify before shipping: the minify mode strips comments and collapses whitespace, turning multi-line PHP into a few compact lines while leaving heredoc bodies intact.
  • Find syntax problems: unbalanced brackets, unterminated strings, block comments and heredocs all report a line and column, so you do not have to wait for a runtime error.

Example

Input

<?php
function add($a,$b){
// 求和
return $a+$b;
}

Output

<?php
function add($a, $b)
{
    // 求和
    return $a + $b;
}

The defaults are a 4-space indent with the opening brace on the next line. In minify mode the same input becomes "<?php function add($a,$b){return $a+$b;}" and the comment is dropped.

Frequently asked questions

Can formatting change what the code does?

No. It is a tokenizer plus a line-based rewriter that only adjusts whitespace and line breaks; expressions are never rewritten and strings, heredoc bodies and comment text are emitted verbatim. It will not insert missing semicolons or swap quote styles.

It says a string quote is unterminated, but the code looks fine?

The usual cause is an unescaped quote inside the string, or smart quotes from Markdown and chat apps replacing ASCII quotes with ’ “ ”. Only ASCII quotes are recognised, so full-width quotes are treated as unterminated.

Minify strips comments — what about /*! licence blocks?

Those go too. Minification removes every comment and collapses whitespace with no exception list. Move a licence header to its own file, or add it back after minifying.

Does it handle files that mix HTML and PHP?

Yes. Anything outside the <?php ?> tags is emitted as-is and excluded from the indentation logic, so template files are not treated as pure PHP.

Is my code uploaded anywhere?

No. Formatting, minification and the syntax check all run locally in JavaScript with no network requests, and the source is never logged.

Keywords:php 格式化php formatterphp 美化php beautifyphp 压缩php minifypsr-12php 缩进php 语法检查

Related tools