Back to Tools

PHP Minifier

Compress PHP code for deployment by stripping non-functional characters

PHP Tool
Source PHP
Minified Output

                

Compress PHP source by stripping comments and whitespace

PHP is compiled on the server, so minifying rarely speeds up a running site, but there are still reasons to shrink source: embedding a snippet in a config field, pasting code into a size-limited form, sending a compact example in a chat, or simply seeing how much of a file is formatting. This tool removes comments and excess spacing and reports how many bytes you saved.

How to minify

  1. Paste your script into the Source PHP box. Load Sample inserts a short documented function and Clear empties the field.
  2. Click Minify PHP.
  3. The Minified Output panel shows a single compact block of code.
  4. Read the statistics bar: original size in KB, minified size in KB and the percentage saved. Then press Copy.

What gets removed

  • Block comments written between slash-asterisk markers, and line comments that begin with two slashes.
  • Line breaks, tabs and repeated spaces, which are collapsed into single spaces.
  • Spaces around braces, semicolons, colons, commas and the characters >, + and ~.

Risks you should know about

The minifier works with text replacement rather than a PHP tokenizer, so it has blind spots that matter in real code:

  • A double slash inside a string, such as a URL beginning with http://, is treated like a comment start, and the rest of that line disappears.
  • Hash-style comments are not recognised. Because all line breaks are turned into spaces, a hash comment can swallow the code that follows it.
  • Heredoc and nowdoc blocks, and anything where line breaks or spacing matter inside a string, may be altered.

Always run the minified result, or lint it with php -l, before relying on it. If your file contains URLs or multi-line strings, test carefully or remove such sections before minifying.

When it is handy

  • Checking how much of a script's size is comments and indentation.
  • Preparing a one-line PHP snippet for a configuration value or an email.
  • Sharing a compact function in a chat message.
  • Comparing size before and after when trimming an embedded template.

The work happens in your browser using JavaScript, and the numbers come from the byte length of the text before and after. Keep your original formatted file as the source of truth and treat the minified version as a build artefact.

Related Tools


Frequently Asked Questions

Will minifying make my PHP site faster?
Usually not by much. PHP is compiled and cached by the server, so whitespace has almost no effect on execution. Minifying is more useful for reducing file size, embedding snippets or sharing compact code.
Why did part of my line vanish after minifying?
The tool treats a double slash as the start of a comment, even inside a string. A URL like http://example.com can therefore cut the rest of the line. Test the output and avoid minifying code containing such strings.
Does it handle # comments?
No. Only slash-asterisk block comments and double-slash line comments are removed. Because line breaks are collapsed, a hash comment can end up commenting out the code after it. Convert those comments first.
What do the size statistics mean?
The bar shows the byte size of your input, the byte size of the minified text in KB, and the saving as a percentage. Files with many comments and indentation see larger savings than already compact code.
Is the minified code safe to deploy?
Only after testing. The minifier is not a PHP parser, so edge cases like heredocs or strings with double slashes may break. Keep your original file, lint the output with php -l and run your tests before use.
Support Chat
We typically reply within minutes

Hello! 👋 Before we start, please tell us your name.