DOMCharacterData::replaceWith
PHP function
Edit on GitHub ✎
(PHP 8)
Replaces the character data with new nodes
Description
DOMCharacterData::replaceWith(DOMNode|string ...$nodes): void
Replaces the character data with new nodes.
Examples
DOMCharacterData::replaceWith example
Replaces the character data with new nodes.
php
<?php
$doc = new DOMDocument;
$doc->loadXML("<container><![CDATA[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::replaceWithDOMCharacterData::afterDOMCharacterData::beforeDOMCharacterData::remove