src/SimpleDOM.php
public function replaceNodes($xpath, SimpleXMLElement $new)
    {
        if (!is_string($xpath)) {
            throw new InvalidArgumentException(
                'Argument 1 passed to replaceNodes() must be a string, ' . gettype($xpath) . ' given'
            );
        }

        $nodes = array();
        foreach ($this->_xpath($xpath) as $node) {
            $nodes[] = $node->replaceSelf($new);
        }

        return $nodes;
    }
public function replaceNodes($xpath, SimpleXMLElement $new)
    {
        if (!is_string($xpath)) {
            throw new InvalidArgumentException(
                'Argument 1 passed to replaceNodes() must be a string, ' . gettype($xpath) . ' given'
            );
        }

        $nodes = array();
        foreach ($this->_xpath($xpath) as $node) {
            $nodes[] = $node->replaceSelf($new);
        }

        return $nodes;
    }
Remove all elements matching a XPath expression

@param    string $xpath XPath expression
@param    SimpleXMLElement $new Replacement node
@throws InvalidArgumentException
@return    array                        Array of replaced nodes on success or FALSE on failure