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

DOMElement::remove

PHP function Edit on GitHub ✎

(PHP 8)

Removes the element

Description

DOMElement::remove(): void

Removes the element.

Examples

DOMElement::remove example

Removes the element.

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

$hello->remove();

echo $doc->saveXML();
?>

The above example will output:

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

See Also

  • DOMElement::after
  • DOMElement::before
  • DOMElement::replaceWith
  • DOMNode::removeChild

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