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