DOMChildNode

DOMChildNode is an interface introduced in PHP 8.0 for DOM nodes that can have siblings. It is implemented by DOMElement, DOMText, DOMComment, DOMProcessingInstruction, and DOMDocumentType.

It provides before() and after() to insert nodes adjacent to the current node, replaceWith() to replace it, and remove() to detach it from its parent.

<?php

    $dom = new DOMDocument;
    $dom->loadHTML('<p>Hello <b>world</b></p>');
    $b = $dom->getElementsByTagName('b')->item(0);
    $b->remove();

?>

Documentation

See also DOMChildNode Class and DOMParentNode Class.

Related : Document Object Model (DOM), Interface, , PHP Native Interfaces, SplSubject

Added in PHP 8.0