PHP comment remover

Remove comments from
PHP code.

Remove comments from PHP files online. Supports //, #, and /* */ comment styles, plus PHPDoc /** ... */ blocks.

Free, no signup Runs in your browser Instant, no upload Works on .php files

Before and after

Real-world PHP code on the left. The same code with every comment removed on the right.

php-input.php
<?php
// Order repository

namespace Acme\Orders;

/**
 * Repository for the orders table.
 */
class OrderRepository
{
    # Database connection
    private \PDO $pdo;

    /* Constructor */
    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo; // store
    }

    /**
     * Find an order by id.
     */
    public function findById(string $id): ?Order
    {
        $sql = "SELECT * FROM orders WHERE id = ?"; // bind safely
        return $this->execute($sql, [$id]);
    }
}
php-output.phpcleaned
<?php

namespace Acme\Orders;

class OrderRepository
{
    private \PDO $pdo;

    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo;
    }

    public function findById(string $id): ?Order
    {
        $sql = "SELECT * FROM orders WHERE id = ?";
        return $this->execute($sql, [$id]);
    }
}
Why use it

Built for PHP specifically.

Legacy PHP codebases accumulate comments at every level, PHPDoc on every function, inline `//` notes, and the occasional `#` shell-style comment. Stripping all three is useful when posting a clean reproducible bug, generating compact code samples, or auditing a diff. Uncommenter handles all PHP comment styles in a single pass.

  • // line, # line, and /* */ block comments removed
  • PHPDoc /** ... */ blocks removed (or preserved via option)
  • Heredoc and nowdoc strings preserved
  • Variables and type declarations untouched
  • Auto-detected from .php and .phtml files
How it works

Strip comments in 30 seconds.

  1. 1

    Open the tool

    Head to uncommenter.com/tool. Nothing to install. Nothing to sign up for.

  2. 2

    Paste your PHP code

    Drop your .php file in, or paste code into the editor. Auto-detection picks up PHP from the extension or file content.

  3. 3

    Click 'Remove Comments'

    The parser walks every character with a real state machine, strings, regex, and other context-sensitive parts are detected and left alone.

  4. 4

    Copy or download

    Grab the cleaned output. Your code never left your browser.

FAQ

PHP questions, answered.

Does it handle # shell-style comments?

+

Yes. PHP supports #, //, and /* */ as comment delimiters; all three are removed.

What about heredoc strings?

+

Heredoc (<<<EOT) and nowdoc (<<<'EOT') strings are recognized as string literals. Comment-like content inside them is preserved.

Will it preserve PHPDoc?

+

By default, PHPDoc blocks are treated as regular block comments and removed. Use the API's `preserveDocstrings` option to keep them.

Other languages

Working in something else?

Plus 35+ more languages supported in the live tool , including HTML, YAML, Dockerfile, Terraform, Solidity, and more.

Try it on your PHP code now.

Free forever. No signup. No upload. Runs entirely in your browser.

Open uncommenter