php8.5
Home/ Manual/ dom / characterdata/ Dom\CharacterData::before

Dom\CharacterData::before

PHP function Edit on GitHub ✎

(PHP 8 >= 8.4.0)

Description

Dom\CharacterData::before(Dom\Node|string ...$nodes): void

Examples

Dom\CharacterData::before example

Adds nodes before the character data.

php
<?php
$doc = Dom\XMLDocument::createFromString("<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" encoding="UTF-8"?>
<container>hello<beautiful/><![CDATA[world]]></container>

See Also

  • Dom\ChildNode::before
  • Dom\CharacterData::after

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