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.
사용법 PHP Minifier
출력
내용 읽기
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
<?phptag 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
- Choose URL Input to pull a raw
.phpfile from a direct link, or switch to Manual Code and paste the source. - Confirm the language is PHP; the Minify mode is already selected on this page.
- Press Process Code.
- Read the output panel and compare the Input and Output character badges.
- Use Copy to place the minified code on the clipboard, or Download to save it with a
.phpextension. - 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
자주 묻는 질문
댓글 (0)
발생한 문제를 자세히 설명해 주시면, 저희가 이를 조사하고 도구를 개선할 수 있습니다.