php8.5
Home/ Manual/ dom / parentnode/ Dom\ParentNode::replaceChildren

Dom\ParentNode::replaceChildren

PHP function Edit on GitHub ✎

(PHP 8 >= 8.4.0)

Description

Dom\ParentNode::replaceChildren(Dom\Node|string ...$nodes): void

Examples

Dom\ParentNode::replaceChildren example

php
<?php
$dom = Dom\HTMLDocument::createFromString('<html><p>hi</p> test <p>hi2</p></html>');

$dom->documentElement->replaceChildren('foo', $dom->createElement('p'), 'bar');
echo $dom->saveHtml();
?>

The above example will output:

output
<!DOCTYPE html><html>foo<p></p>bar</html>

Source: reference/dom/dom/parentnode/replacechildren.xml · from the official PHP manual (php/doc-en)