DOMElement::prepend
PHP function
Edit on GitHub ✎
(PHP 8)
Prepends nodes before the first child node
Description
DOMElement::prepend(DOMNode|string ...$nodes): void
Prepends one or many nodes to the list of children before the first child node.
Examples
DOMElement::prepend example
Prepends nodes in the container element.
php
<?php
$doc = new DOMDocument;
$doc->loadXML("<container> world</container>");
$world = $doc->documentElement;
$world->prepend($doc->createElement("hello"), "beautiful");
echo $doc->saveXML();
?>The above example will output:
output
<?xml version="1.0"?>
<container><hello/>beautiful world</container>See Also
DOMParentNode::prependDOMElement::append