QueryPath\DOMQuery::replaceAll PHP Method

replaceAll() public method

This is the reverse of replaceWith. Unlike jQuery, DOMQuery cannot assume a default document. Consequently, you must specify the intended destination document. If it is omitted, the present document is assumed to be tthe document. However, that can result in undefined behavior if the selector and the replacement are not sufficiently distinct.
See also: remove()
See also: replaceWith()
Deprecation: Due to the fact that this is not a particularly friendly method, and that it can be easily replicated using {@see \replaceWith()}, it is to be considered deprecated.
public replaceAll ( string $selector, DOMDocument $document )
$selector string The selector.
$document DOMDocument The destination document.
    public function replaceAll($selector, \DOMDocument $document)
    {
        $replacement = $this->size() > 0 ? $this->getFirstMatch() : $this->document->createTextNode('');
        $c = new QueryPathEventHandler($document);
        $c->find($selector);
        $temp = $c->getMatches();
        foreach ($temp as $item) {
            $node = $replacement->cloneNode();
            $node = $document->importNode($node);
            $item->parentNode->replaceChild($node, $item);
        }
        return QueryPath::with($document, null, $this->options);
    }