(PHP 8 >= 8.3.0)
DOMElement::insertAdjacentElement — Insert adjacent element
Inserts an element at a relative position given by where
.
where
beforebegin
- 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.element
The element to insert.
Return DOMElement or null
on failure.
Example #1 DOMElement::insertAdjacentElement() example
<?php
$dom = new DOMDocument();
$dom->loadXML('<?xml version="1.0"?><container><p>foo</p></container>');
$container = $dom->documentElement;
$p = $container->firstElementChild;
$p->insertAdjacentElement('beforebegin', $dom->createElement('A'));
echo $dom->saveXML();
?>
The above example will output:
<?xml version="1.0"?> <container><A/><p>foo</p></container>
Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!
Check out: eBank.nz (Art Generator) |
Netwrck.com (AI Tools) |
Text-Generator.io (AI API) |
BitBank.nz (Crypto AI) |
ReadingTime (Kids Reading) |
RewordGame |
BigMultiplayerChess |
WebFiddle |
How.nz |
Helix AI Assistant