DOMElement::insertAdjacentText
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.3.0)
Insert adjacent text
Description
DOMElement::insertAdjacentText(string $where, string $data): void
Inserts text at a relative position given by where.
Parameters
wherebeforebegin- Insert before the target element.afterbegin- Insert as the first child of the target element.beforeend- Insert as the last child of the target element.afterend- Insert after the target element.
dataThe string to insert.
Return Values
Void
Examples
DOMElement::insertAdjacentText example
php
<?php
$dom = new DOMDocument();
$dom->loadXML('<?xml version="1.0"?><container><p>H</p></container>');
$container = $dom->documentElement;
$p = $container->firstElementChild;
$p->insertAdjacentText("afterbegin", "P");
$p->insertAdjacentText("beforeend", "P");
echo $dom->saveXML();
?>The above example will output:
output
<?xml version="1.0"?>
<container><p>PHP</p></container>See Also
DOMElement::insertAdjacentElement