Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created June 26, 2013 15:07
Show Gist options
  • Save ajcrites/5868194 to your computer and use it in GitHub Desktop.
Save ajcrites/5868194 to your computer and use it in GitHub Desktop.
DOMNodeList from `xpath::query` weird parents
<?php
$nodes = <<<HTML
<div>
div
<p> ... </p>
</div>
HTML;
$dom = new DOMDocument;
$dom->loadHTML($nodes);
$xpath = new DOMXPath($dom);
foreach ($xpath->query('//*') as $node) {
var_dump($node->parentNode);
$node->parentNode->removeChild($node);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment