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 .

Indent
Off by default: conditional comments and build markers look like ordinary comments, so removing them is your call. Note SQL comments can carry real meaning (query hints in some databases live in comments), so check before stripping. A /*! banner comment is always kept, the usual convention for a licence header.

Drop a PHP file here

or or paste below

Up to 4 MB · nothing uploaded

{{ inBytes }}
{{ outBytes }}
{{ status }}

{{ commentWarning }}

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.

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.