<?php
$doc = new DOMDocument;
$doc->loadHTML('<html><body id="x"><div id="y"></div></body></html>');
$body = $doc->getElementById('x');
$div = $doc->getElementById('y');
$body->removeChild($div);
echo '1: ' . ( $doc->getElementById('y') ? $doc->getElementById('y')->tagName : 'null' ) . PHP_EOL;
$div->setIdAttribute( 'id', true );
echo '2: ' . ( $doc->getElementById('y') ? $doc->getElementById('y')->tagName : 'null' ) . PHP_EOL;
- Output for 8.1.21 - 8.1.33, 8.2.8 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- 1: null
2: null
- Output for 7.4.25 - 7.4.33, 8.0.12 - 8.0.30, 8.1.0 - 8.1.20, 8.2.0 - 8.2.7
- 1: div
2: div
- Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.24, 8.0.0 - 8.0.11
- 1: div
2: null
preferences:
113.96 ms | 409 KiB | 5 Q