Home » Developer Tools » PHP Minifier
Paste PHP and get a smaller version in seconds, with strings, heredoc, and HTML kept intact.
Last updated 13 November 2026
Your code never leaves your browser. Everything runs locally on your device.
PHP files often carry comments and extra whitespace that add nothing at run time. The PHP Minifier removes comments and collapses whitespace inside your PHP blocks, so your files become smaller without changing what they do.
PHP needs careful handling: text that looks like a comment inside a string is not a comment, heredoc content must never be touched, and HTML mixed with PHP must be left alone. This tool handles all three. Everything runs in your browser, so your code is never uploaded to a server.
A PHP minifier takes readable PHP code and removes every byte a browser does not need when the file is stored or sent. It deletes comments, collapses extra spaces and line breaks, and drops blank lines inside PHP blocks. The code itself stays the same, so the file still runs exactly as before. Use it on the file you publish, and keep your readable original for editing.
| What is removed | Example |
|---|---|
| Comments | Notes inside //, # or /* */ are deleted |
| Extra spaces and line breaks | Long gaps collapse to one space or nothing |
| Blank lines | Empty lines inside PHP blocks are removed |
Strings, heredoc and nowdoc blocks, HTML outside PHP blocks, and variable and function names are all left alone. A string that contains // or /* */ still works, because the tool reads it as text, not as a comment. If you ever need to read a minified file again, the PHP Beautifier formats it back into neat readable code.
Minifying only shrinks a file. It does not change what the code does, and there are a few things it will never do for you.
Minify your other code too: use the HTML Minifier for your pages, the CSS Minifier for your styles, and the JavaScript Minifier for your scripts, so the whole page ships smaller.
Here is a small function run through the tool, with the exact numbers:
Input, 110 characters:
<?php
// Say hello to a visitor
function greet($name) {
return "Hello, " . $name;
}
echo greet("Ada");
?>
Output, 72 characters:
<?php function greet($name){return"Hello, ".$name;}echo greet("Ada"); ?>
The output is 72 characters, down from 110. That is 38 characters removed, and 38 divided by 110 is 0.345, so the file is about 35 percent smaller. The string "Hello, " keeps its comma and space, and the comment line is gone. Try the same code yourself with the Load Sample button above: the sample shrinks from 264 characters to 208 characters, about 21 percent smaller, with its strings and heredoc kept intact.
Yes, it is completely free with no sign up.
Yes. Minifying only removes comments and extra whitespace inside PHP blocks. Your logic, strings, and HTML stay unchanged.
No. Text inside strings, heredoc, and nowdoc blocks is preserved exactly, even when it contains comment markers.
Yes. HTML outside PHP blocks is left untouched, and only the PHP blocks themselves are minified.
No. All minifying happens in your browser on your own device, so your code never leaves your computer.
It gives a small saving in parsing work and file size. For real PHP speed, a good OPcache setup matters more, and minifying is best seen as a tidy extra, not a replacement for it.
That depends on how many comments and extra spaces your file holds. The sample on this page shrinks from 264 characters to 208 characters, about 21 percent smaller, and the worked example on this page shrinks from 110 characters to 72 characters, about 35 percent smaller. A file that is already tidy shrinks only a little. Paste your own code into the tool above and the Change figure shows your exact result.
When the box is ticked, every comment is removed, including //, # and /* */ comments. When you untick it, your comments stay in the output and only extra whitespace is removed. The box is ticked when the page loads, so the smallest output is the default.
No. When the Strip comments box is ticked, all comments are removed, including licence notes. The tool has no option to keep licence comments, so keep the licence text in your readable source file and in any copy you share with others.
Only a little. PHP runs on the server, so a smaller file saves a little parsing work and bandwidth. It does not speed up page loads the way minifying JavaScript or CSS does. For real PHP speed, a good OPcache setup matters more than minifying.
No. Variable and function names stay exactly as written, and no code is removed or rearranged. That is deliberate: PHP lets code build names while it runs, so renaming could break working code. Minifying does not hide your code, because anyone can still read it.
No. The tool does not validate your code, so broken PHP is processed as plain text and returned without a warning. Test the minified output on a copy of your project before you use it live, and keep your original file safe.
If your PHP needs tidying up instead of shrinking, try the PHP beautifier to format it into clean readable code.