php8.5
Home/ Manual/ dom / domdocumentfragment/ DOMDocumentFragment::prepend

DOMDocumentFragment::prepend

PHP function Edit on GitHub ✎

(PHP 8)

Prepends nodes before the first child node

Description

DOMDocumentFragment::prepend(DOMNode|string ...$nodes): void

Prepends one or many nodes to the list of children before the first child node.

Examples

DOMDocumentFragment::prepend example

Prepends nodes before the fragment root.

php
<?php
$doc = new DOMDocument;
$fragment = $doc->createDocumentFragment();
$fragment->appendChild($doc->createElement("world"));

$fragment->prepend($doc->createElement("hello"), "beautiful");

echo $doc->saveXML($fragment);
?>

The above example will output:

output
<hello/>beautiful<world/>

See Also

  • DOMParentNode::prepend
  • DOMDocumentFragment::append

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