private function unwrapContents(DOMNode $node, DOMNode $child)
    {
        // Preserve the content by adding the child nodes to the parent
        $next = $child->nextSibling;
        if ($next === null)
            $next = $child;

        if ($child->childNodes !== null)
        {
            $l = $child->childNodes->length;
            for ($i = $l - 1; $i >= 0; --$i)
            {
                // This try/catch seems not necessary as it does not actually
                // check HTML rules, it will gladly accept <option> in a <p>,
                // or <li> in a <div> for example.
                //
                //try
                //{
                $sub = $child->childNodes[$i];
                $next = $node->insertBefore($sub, $next);
                //}
                //catch (DOMException $ex)
                //{}
            }
        }

        // Finally, remove the node
        $node->removeChild($child);

        // Next is now either:
        // 1) the last inserted child == the top of the list of new nodes
        // 2) if the unwrapped node had no children, the next node
        // 3) if the unwrapped node was the last node, it's the unwrapped node itself
        //
        // 1 and 2 do what is expected, in the case of 3, there is no next node,
        // so null should be returned, rather than the removed node.
        return ($next !== null && $next->isSameNode($child)) ? null : $next;
    }
private function unwrapContents(DOMNode $node, DOMNode $child)
    {
        // Preserve the content by adding the child nodes to the parent
        $next = $child->nextSibling;
        if ($next === null)
            $next = $child;

        if ($child->childNodes !== null)
        {
            $l = $child->childNodes->length;
            for ($i = $l - 1; $i >= 0; --$i)
            {
                // This try/catch seems not necessary as it does not actually
                // check HTML rules, it will gladly accept <option> in a <p>,
                // or <li> in a <div> for example.
                //
                //try
                //{
                $sub = $child->childNodes[$i];
                $next = $node->insertBefore($sub, $next);
                //}
                //catch (DOMException $ex)
                //{}
            }
        }

        // Finally, remove the node
        $node->removeChild($child);

        // Next is now either:
        // 1) the last inserted child == the top of the list of new nodes
        // 2) if the unwrapped node had no children, the next node
        // 3) if the unwrapped node was the last node, it's the unwrapped node itself
        //
        // 1 and 2 do what is expected, in the case of 3, there is no next node,
        // so null should be returned, rather than the removed node.
        return ($next !== null && $next->isSameNode($child)) ? null : $next;
    }
private function unwrapContents ( DOMNode $ node , DOMNode $ child ) { // Preserve the content by adding the child nodes to the parent $ next = $ child -> nextSibling ; if ( $ next === null ) $ next = $ child ; if ( $ child -> childNodes !== null ) { $ l = $ child -> childNodes -> length ; for ( $ i = $ l - 1 ; $ i >= 0 ; -- $ i ) { // This try/catch seems not necessary as it does not actually // check HTML rules, it will gladly accept <option> in a <p>, // or <li> in a <div> for example. // //try //{ $ sub = $ child -> childNodes [ $ i ] ; $ next = $ node -> insertBefore ( $ sub , $ next ) ; //} //catch (DOMException $ex) //{} } } // Finally, remove the node $ node -> removeChild ( $ child ) ; // Next is now either: // 1) the last inserted child == the top of the list of new nodes // 2) if the unwrapped node had no children, the next node // 3) if the unwrapped node was the last node, it's the unwrapped node itself // // 1 and 2 do what is expected, in the case of 3, there is no next node, // so null should be returned, rather than the removed node. return ( $ next !== null && $ next -> isSameNode ( $ child ) ) ? null : $ next ; }
Helper function to unwrap the contents of a node and remove the node.
@param $node DOMNode The node from which to remove the child
@param $child DOMNode The child to remove from the node
@return The first newly added node, or if none were added, the next sibling node
Helper function to unwrap the contents of a node and remove the node .