Developer Tool updated 1 week ago

PHP Minifier

Use this free PHP minifier to strip comments and whitespace from PHP source online. Paste your code or load it from a raw file URL, press Process Code, and download a compact .php file. The minifier uses PHP's own php_strip_whitespace(), so strings and identifiers stay untouched.

Always Free Easy to use Instant results Private and secure

Use PHP Minifier

Paste a direct code file URL to load its contents into the editor.

Output

Done

Read Content

Learn how the tool works and when to use it.

What this PHP minifier does

Paste PHP source into the editor or load it from a URL, press Process Code, and the tool returns the same script with comments and unnecessary whitespace stripped out. Under the hood it calls PHP's own php_strip_whitespace() function, so the reduction follows the PHP tokenizer rather than a regular-expression guess: comments are removed, blank lines disappear, and the code is packed together without touching the meaning of the script.

It is the opposite of the PHP formatter in the same suite. The formatter adds indentation and spacing for readability; the minifier removes them to reduce the file size. Both tools use the same editor and the same server-side processing, and both are limited to 200,000 characters of input per request.

What is removed and what is kept

  • Removed: single-line comments (// and #), block and doc comments (/* ... */, /** ... */), indentation, trailing spaces, blank lines, and whitespace between tokens where PHP does not need it.
  • Kept: every string literal exactly as written, including spaces and line breaks inside quotes, plus heredoc and nowdoc bodies. Values are data, so the tokenizer does not collapse them.
  • Kept: variable names, function names, class names, constants, operators and control flow. Nothing is renamed and nothing is restructured.
  • Kept: the <?php tag when your input had one. If it did not, a tag is added so the file can be parsed and then removed again before the result is returned.

Because only comments and whitespace are touched, the minified file behaves the same as the original. This is size reduction, not obfuscation: anyone who opens the output can still read the structure and every identifier.

How much smaller does it get?

The saving depends entirely on how comment-heavy and generously spaced the original is. A file full of docblocks and aligned arrays can shrink by a large fraction; a file that is already terse may barely change. The editor shows an Input and an Output character badge after processing, so you can see the before and after counts directly rather than guessing at a percentage.

Remember that characters are not bytes. The badges measure length, and the actual file-size change depends on the encoding and the content of the strings. Treat the counters as a quick comparison, not an exact byte count.

How to minify PHP online

  1. Choose URL Input to pull a raw .php file from a direct link, or switch to Manual Code and paste the source.
  2. Confirm the language is PHP; the Minify mode is already selected on this page.
  3. Press Process Code.
  4. Read the output panel and compare the Input and Output character badges.
  5. Use Copy to place the minified code on the clipboard, or Download to save it with a .php extension.
  6. Press Clear to empty both panels when you are done.

Minify or beautify?

Use the minifier when you are packaging the file for distribution, comparing two versions by size, or preparing a compact copy to ship. Use the formatter when you are reading, reviewing or handing the code to someone else. A practical workflow keeps the readable version in version control and produces the minified copy only as a build artefact, so the diff you review is never a wall of collapsed code.

It is worth knowing that production PHP is normally served through an opcode cache such as OPcache, which already compiles the script once and reuses the result. That reduces the everyday benefit of minifying PHP compared with front-end assets. The tool is still useful for measuring comment overhead and for producing small distribution copies, but it is not a substitute for a cache or a build pipeline.

When the output comes back empty

php_strip_whitespace() has to tokenize the file before it can strip anything, so PHP that does not parse cannot be minified. A missing semicolon, an unbalanced brace or bracket, an unterminated string, or a stray closing tag can leave you with an empty output panel instead of a result. If that happens, format the same code with the PHP formatter first: a syntax error there produces a clear failure message, which tells you where to look before you try to minify again.

The 200,000-character ceiling is the other common stop. Very large files need to be split, minified in parts, and rejoined, or processed with the same function locally, where no request limit applies.

Privacy: the code leaves your browser

This is not a client-side tool. The editor posts your PHP to the server, where the minifier runs, and the temporary file is deleted afterwards. That means you should remove database passwords, API keys, tokens and anything else sensitive before pasting. If the code must stay private, run a minifier on your own machine instead.

Comments you should keep a copy of

Because every comment is treated as removable, anything that lives in a comment disappears with it. That includes licence and copyright headers, file-level notes, and annotations that tooling reads from docblocks, such as type hints for static analysis, test annotations, or mapping metadata used by some frameworks. The code still runs without them, but a tool that expected the annotation may stop understanding the file. Before you replace a source file with its minified version, check whether your project depends on docblock content, and keep the annotated original in version control. The minified download is best treated as a build output, not as the file you edit next.

Common mistakes

  • Expecting obfuscation. The output is readable. Names and structure are untouched, so it does not hide logic from anyone.
  • Minifying code with syntax errors. The tokenizer stops, and an empty result is the usual symptom.
  • Keeping the minified copy in version control. It makes future diffs unreadable; keep the source and generate the minified file.
  • Assuming a huge saving. Comment-light files shrink only a little; the character badges show the real result.
  • Pasting secrets. The code is uploaded for processing, so sanitise it first.
  • Confusing it with a formatter. This page removes structure; the formatter adds it.

Limitations

The tool minifies one PHP file per request, up to 200,000 characters, and it removes only comments and whitespace. It does not rename identifiers, combine statements, inline functions, resolve includes, execute the script, or check that the logic is correct. It does not produce a byte-level size report, only character counts, and it cannot minify files that fail to tokenize. For front-end assets such as JavaScript and CSS, use the dedicated minifiers, which use their own parsers rather than the PHP tokenizer.

Frequently Asked Questions

FAQ

Short answers for the questions users ask before trusting the result.

Comments, indentation, blank lines and unnecessary whitespace. It uses PHP's php_strip_whitespace(), so string contents and all identifiers are left exactly as they were.

No. Only comments and whitespace are removed, so the behaviour is the same. It is size reduction, not obfuscation.

After processing, the editor shows the Input and Output character counts. Compare them to see the reduction; they are character counts, not exact byte sizes.

Usually because the PHP has a syntax error and the tokenizer could not parse it. Run the code through the PHP formatter to get a clearer error, fix it, then minify again.

The request accepts up to 200,000 characters. Split larger files into parts or run the same function locally without a request limit.

Yes. The minifier runs on the server, so the code is sent there and the temporary file is removed afterwards. Strip secrets before pasting.

Comments (0)

For user discussion, edge cases, and follow-up tips.
Leave a comment
Your comment will appear publicly after submission.
No comments yet. Be the first to comment!
Let Us Know!
Report an issue with this tool

Describe the issue you encountered so we can investigate and improve the tool.

What helps most
Include the input, expected result, actual result, browser/device, and a screenshot when helpful.
The screenshot button captures the page in the browser and attaches the generated image to this form.
Full-page screenshot
Captured in your browser with newisty.
No screenshot captured yet.
Tool Report