private static function removeProceedingNodes($domNode, $topNode)
    {
        $nextNode = $domNode->nextSibling;

        if ($nextNode !== null) {
            self::removeProceedingNodes($nextNode, $topNode);
            $domNode->parentNode->removeChild($nextNode);
        } else {
            //scan upwards till we find a sibling
            $curNode = $domNode->parentNode;
            while ($curNode !== $topNode) {
                if ($curNode->nextSibling !== null) {
                    $curNode = $curNode->nextSibling;
                    self::removeProceedingNodes($curNode, $topNode);
                    $curNode->parentNode->removeChild($curNode);
                    break;
                }
                $curNode = $curNode->parentNode;
            }
        }
    }
private static function removeProceedingNodes($domNode, $topNode)
    {
        $nextNode = $domNode->nextSibling;

        if ($nextNode !== null) {
            self::removeProceedingNodes($nextNode, $topNode);
            $domNode->parentNode->removeChild($nextNode);
        } else {
            //scan upwards till we find a sibling
            $curNode = $domNode->parentNode;
            while ($curNode !== $topNode) {
                if ($curNode->nextSibling !== null) {
                    $curNode = $curNode->nextSibling;
                    self::removeProceedingNodes($curNode, $topNode);
                    $curNode->parentNode->removeChild($curNode);
                    break;
                }
                $curNode = $curNode->parentNode;
            }
        }
    }
private static function removeProceedingNodes ( $ domNode , $ topNode ) { $ nextNode = $ domNode -> nextSibling ; if ( $ nextNode !== null ) { self :: removeProceedingNodes ( $ nextNode , $ topNode ) ; $ domNode -> parentNode -> removeChild ( $ nextNode ) ; } else { //scan upwards till we find a sibling $ curNode = $ domNode -> parentNode ; while ( $ curNode !== $ topNode ) { if ( $ curNode -> nextSibling !== null ) { $ curNode = $ curNode -> nextSibling ; self :: removeProceedingNodes ( $ curNode , $ topNode ) ; $ curNode -> parentNode -> removeChild ( $ curNode ) ; break ; } $ curNode = $ curNode -> parentNode ; } } }
Removes all nodes after the current node.
@param  DOMNode|DOMElement $domNode
@param  DOMNode|DOMElement $topNode
@return void
Removes all nodes after the current node .