php8.5
Home/ Manual/ dom / domcharacterdata/ DOMCharacterData::before

DOMCharacterData::before

PHP function Edit on GitHub ✎

(PHP 8)

Adds nodes before the character data

Description

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

Adds the passed nodes before the character data.

Examples

DOMCharacterData::before example

Adds nodes before the character data.

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

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

echo $doc->saveXML();
?>

The above example will output:

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

See Also

  • DOMChildNode::before
  • DOMCharacterData::after

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