pQuery\HtmlFormatter::minify_html PHP Method

minify_html() static public method

Minifies HTML / removes unneeded whitespace
static public minify_html ( DomNode &$root, boolean $strip_comments = true, boolean $recursive = true )
$root DomNode
$strip_comments boolean
$recursive boolean
    static function minify_html(&$root, $strip_comments = true, $recursive = true)
    {
        if ($strip_comments) {
            foreach ($root->select(':comment', false, $recursive, true) as $c) {
                $prev = $c->getSibling(-1);
                $next = $c->getSibling(1);
                $c->delete();
                if ($prev && $next && $prev->isText() && $next->isText()) {
                    $prev->text .= $next->text;
                    $next->delete();
                }
            }
        }
        foreach ($root->select('(!pre + !xmp + !style + !script + !"?php" + !"~text~" + !"~comment~"):not-empty > "~text~"', false, $recursive, true) as $c) {
            $c->text = preg_replace('`\\s+`', ' ', $c->text);
        }
    }