PHP Minifier
Compress PHP code for deployment by stripping non-functional characters
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
- Paste your script into the Source PHP box. Load Sample inserts a short documented function and Clear empties the field.
- Click Minify PHP.
- The Minified Output panel shows a single compact block of code.
- 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