DOMElement::replaceChildren
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.3.0)
Replace children in element
Description
DOMElement::replaceChildren(DOMNode|string ...$nodes): void
Replaces the children in the element with new nodes.
Examples
DOMElement::replaceChildren example
Replaces the children with new nodes.
php
<?php
$doc = new DOMDocument;
$doc->loadXML("<container><hello/></container>");
$container = $doc->documentElement;
$container->replaceWith("beautiful", $doc->createElement("world"));
echo $doc->saveXML();
?>The above example will output:
output
<?xml version="1.0"?>
beautiful
<world/>See Also
DOMParentNode::replaceChildrenDOMElement::replaceWithDOMElement::afterDOMElement::beforeDOMElement::remove