private function removeBadTags(): self {
        $lists = [
            "[%s^='%s']" => $this->startsWithNodes,
            "[%s*='%s']" => $this->searchNodes,
            "[%s$='%s']" => $this->endsWithNodes,
            "[%s='%s']" => $this->equalsNodes,
        ];

        $attrs = [
            'id',
            'class',
            'name',
        ];

        $exceptions = array_map(function($value) {
            return ':not(' . $value . ')';
        }, $this->exceptionSelectors);

        $exceptions = implode('', $exceptions);

        foreach ($lists as $expr => $list) {
            foreach ($list as $value) {
                foreach ($attrs as $attr) {
                    $selector = sprintf($expr, $attr, $value) . $exceptions;

                    foreach ($this->document()->find($selector) as $node) {
                        $node->remove();
                    }
                }
            }
        }

        return $this;
    }
private function removeBadTags(): self {
        $lists = [
            "[%s^='%s']" => $this->startsWithNodes,
            "[%s*='%s']" => $this->searchNodes,
            "[%s$='%s']" => $this->endsWithNodes,
            "[%s='%s']" => $this->equalsNodes,
        ];

        $attrs = [
            'id',
            'class',
            'name',
        ];

        $exceptions = array_map(function($value) {
            return ':not(' . $value . ')';
        }, $this->exceptionSelectors);

        $exceptions = implode('', $exceptions);

        foreach ($lists as $expr => $list) {
            foreach ($list as $value) {
                foreach ($attrs as $attr) {
                    $selector = sprintf($expr, $attr, $value) . $exceptions;

                    foreach ($this->document()->find($selector) as $node) {
                        $node->remove();
                    }
                }
            }
        }

        return $this;
    }
private function removeBadTags ( ) : self { $ lists = [ "[%s^='%s']" => $ this -> startsWithNodes , "[%s*='%s']" => $ this -> searchNodes , "[%s$='%s']" => $ this -> endsWithNodes , "[%s='%s']" => $ this -> equalsNodes , ] ; $ attrs = [ 'id' , 'class' , 'name' , ] ; $ exceptions = array_map ( function ( $ value ) { return ':not(' . $ value . ')' ; } , $ this -> exceptionSelectors ) ; $ exceptions = implode ( '' , $ exceptions ) ; foreach ( $ lists as $ expr => $ list ) { foreach ( $ list as $ value ) { foreach ( $ attrs as $ attr ) { $ selector = sprintf ( $ expr , $ attr , $ value ) . $ exceptions ; foreach ( $ this -> document ( ) -> find ( $ selector ) as $ node ) { $ node -> remove ( ) ; } } } } return $ this ; }
Remove unwanted junk elements based on pre-defined CSS selectors

@return self
Remove unwanted junk elements based on pre - defined CSS selectors