Dutch PHP Conference 2025 - Call For Papers

DOMDocumentFragment::prepend

(PHP 8)

DOMDocumentFragment::prependPrepends nodes before the first child node

Опис

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

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

Параметри

nodes

The nodes to prepend. Strings are automatically converted to text nodes.

Значення, що повертаються

Не повертає значень.

Помилки/виключення

DOM_HIERARCHY_REQUEST_ERR

Виникає, якщо тип цього вузла не дозволяє тип дочірнього вузла, котрий передано в параметр nodes, або якщо вузол, який потрібно додати, є одним із предків цього вузла або ним самим.

DOM_WRONG_DOCUMENT_ERR

Виникає, якщо один з переданих nodes було створено не в тому документі, що і цей вузол.

Журнал змін

Версія Опис
8.3.0 Calling this method on a node without an owner document now works. Раніше викидалося виключення DOMException з кодом DOM_HIERARCHY_REQUEST_ERR.

Приклади

Приклад #1 DOMDocumentFragment::prepend() example

Prepends nodes before the fragment root.

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

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

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

Поданий вище приклад виведе:

<hello/>beautiful<world/>

Прогляньте також

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top