php8.5
Home/ Manual/ dom / domelement/ DOMElement::append

DOMElement::append

PHP function Edit on GitHub ✎

(PHP 8)

Appends nodes after the last child node

Description

DOMElement::append(DOMNode|string ...$nodes): void

Appends one or many nodes to the list of children after the last child node.

Examples

DOMElement::append example

Appends nodes in the container element.

php
<?php
$doc = new DOMDocument;
$doc->loadXML("<container>hello </container>");
$world = $doc->documentElement;

$world->append("beautiful", $doc->createElement("world"));

echo $doc->saveXML();
?>

The above example will output:

output
<?xml version="1.0"?>
<container>hello beautiful<world/></container>

See Also

  • DOMParentNode::append
  • DOMElement::prepend

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