Skip to content
UniKit

PHP source compressor

Compress PHP source: strip `//`, `#` and block comments and collapse redundant whitespace while keeping strings, heredoc / nowdoc bodies and the `<?php` / `?>` tags intact (lexical scanning prevents treating // inside a string as a comment). Optionally keep line breaks or block comments. Round-trips with php-uncompress: the restored code behaves identically, only whitespace differs.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Input

Result

The result can be copied directly.

Paste PHP source to compress it

Characters: 0 · Comments removed: 0 · Characters saved: 0

What this tool does

  • Shrink inline PHP snippets to reduce payload size.
  • Flatten a heavily commented class into one line for diffing.
  • Pair with php-uncompress to verify compression safety.

Example

Input

<?php
// user service
class UserService
{
    /** greeting */
    public function greet(string $name): string
    {
        $prefix = 'Hello, ';   // prefix
        return $prefix . $name . "!";
    }
}

Output

<?php class UserService{public function greet(string $name): string{$prefix = 'Hello, ';return $prefix . $name . "!";}}

Compression only touches whitespace and comments; statements stay identical and string / heredoc contents are preserved character by character.

Frequently asked questions

Could it delete // inside a string?

No. PHP is lexically scanned first: single / double quoted strings and heredoc / nowdoc bodies are kept as whole tokens, and only real comment tokens are removed.

Is the compressed code still runnable?

Yes. Only comments are removed, whitespace is collapsed and redundant spaces around `;` and `}` are dropped, so statements are unchanged. Pair with php-uncompress to compare line by line.

Why is the heredoc not flattened to one line?

A heredoc / nowdoc terminator must sit on its own line, so the compressor preserves its line breaks; source containing heredocs cannot become a single line.

How is "characters saved" computed?

Original length minus compressed length. Files with many comments and deep indentation benefit most.

Keywords:php compress

Related tools