Dutch PHP Conference 2025 - Call For Papers

DOMCharacterData::before

(PHP 8)

DOMCharacterData::beforeAdds nodes before the node

Опис

public DOMCharacterData::before(DOMNode|string ...$nodes): void

Adds the passed nodes before the node.

Параметри

nodes

Nodes to be added before the node. 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 a parent is now a no-op to align the behaviour with the DOM specification. Раніше викидалося виключення DOMException з кодом DOM_HIERARCHY_REQUEST_ERR.

Приклади

Приклад #1 DOMCharacterData::before() example

Adds nodes before the character data.

<?php
$doc
= new DOMDocument;
$doc->loadXML("<container><![CDATA[world]]></container>");
$cdata = $doc->documentElement->firstChild;

$cdata->before("hello", $doc->createElement("beautiful"));

echo
$doc->saveXML();
?>

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

<?xml version="1.0"?>
<container>hello<beautiful/><![CDATA[world]]></container>

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

add a note

User Contributed Notes

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