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