DOMDocumentFragment::replaceChildren
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.3.0)
Replace children in fragment
Description
DOMDocumentFragment::replaceChildren(DOMNode|string ...$nodes): void
Replaces the children in the document fragment with new nodes.
Examples
DOMDocumentFragment::replaceChildren example
Replaces the children with new nodes.
php
<?php
$doc = new DOMDocument;
$doc->loadXML("<container><hello/></container>");
$fragment = $doc->createDocumentFragment();
$fragment->append("hello");
$fragment->replaceChildren("beautiful", $doc->createElement("world"));
echo $doc->saveXML($fragment);
?>The above example will output:
output
beautiful<world/>See Also
DOMParentNode::replaceChildrenDOMDocumentFragment::appendDOMDocumentFragment::prepend