PHP Minifier & Beautifier
Format PHP source or strip it down — HTML outside the PHP tags and heredoc blocks stay exactly as written, so a template file survives intact.
Only whitespace and comments are ever changed. No PHP token is renamed, reordered or removed, so the output cannot behave differently from your input. That also means the size reduction is smaller than tools which rewrite your code — no variable mangling, no dead-code removal — no merged selectors, no collapsed shorthands — and because SQL needs whitespace between tokens, it can only be collapsed, never removed. This formats your source; it does not compile it. Your types are preserved, not stripped.
/*! banner comment is always kept, the usual
convention for a licence header.
Drop a PHP file here
Up to 4 MB · nothing uploaded
{{ error }}
{{ commentWarning }}
Verified — every token preserved
The output was re-tokenized and compared against the input: all {{ tokenCount }} code tokens are identical, in the same order. Only whitespace and comments differ.
Output rejected
The result did not survive the token check, so it was discarded rather than shown to you. This is a bug in the tool, not in your code — please treat the input as unformatted.
Your PHP is tokenized and reformatted entirely in your browser. Nothing you paste or drop is ever uploaded to a server.
A PHP file is usually two languages at once
Everything outside <?php … ?> is literal output — normally HTML — and this
tool copies it through byte for byte. Only the code inside the tags is reformatted. That is why
a template made mostly of markup barely shrinks while a file of pure logic shrinks a great
deal, and it is deliberate: recursively reformatting the embedded HTML as well would mean
getting the boundary between the two exactly right, and getting it wrong corrupts the file
rather than merely making it ugly.
Heredocs, nowdocs and interpolated strings
Heredoc and nowdoc blocks are whitespace-significant from the opening marker to the closing
one, so they are treated as a single opaque unit — including one that happens to contain
?>, which a naive scanner would read as the end of the PHP block. Double-quoted
strings keep their $variable interpolation exactly as written.
One PHP quirk worth knowing
A // or # comment in PHP ends at a closing tag as well as at a
newline, so // note ?> leaves PHP mode right there. Tools that only look for
the newline get this wrong and swallow the rest of the file; this one accounts for it.
Formatting the HTML separately
Run the markup through the HTML Minifier
& Beautifier, which handles pre, script and inline-element
spacing correctly.
Frequently asked questions
What does this do to the HTML in a PHP template?
Nothing at all. Everything outside the PHP tags is literal output and is copied through byte for byte, so a template that is mostly HTML with embedded PHP keeps its markup exactly as written. Only the code inside the tags is reformatted.
Are heredoc and nowdoc blocks safe?
Yes. Their contents are whitespace-significant from start to finish, so they are treated as one opaque block and never reflowed — including a heredoc that happens to contain a PHP closing tag, which a naive scanner would mistake for the end of the code.
Why did minifying my PHP file barely shrink it?
Because most of the file was probably HTML rather than PHP, and the HTML is intentionally left alone. Files that are mostly code shrink far more than templates that are mostly markup.
Does it strip comments?
Yes when minifying, including the // and # single-line forms and /* */ blocks. Note that PHP ends a single-line comment at a closing PHP tag as well as at a newline, which this tool accounts for.
Is my PHP source uploaded anywhere?
No. Tokenizing and formatting run entirely in your browser. Nothing is sent to a server, which matters since PHP source often contains database credentials or API keys.