<?php
$txt = <<<EOT
<p>The breed was first...</p>
<p>Semencic credits his...</p>
<h1>Appearance</h1>
<p>The breed's distinctive...</p>
<p>It should be symmetrical...</p>
<figure id="attachment_6" style="width: 840px" class="wp-caption alignnone">
<img class="size-large wp-image-6" src="...jpg" alt="boerboel appearance" width="840" height="746">
<figcaption class="wp-caption-text">The dog appearance.</figcaption>
</figure>
<h1>Requirements</h1>
<p>Prospective owners....</p>
<p>These dogs....</p>
<h2>A Little Warning!</h2>
<p>If you are considering...</p>
<blockquote>
<p>According to...</p>
<p>Source: http://...</p>
</blockquote>
<p>Although more suitable...</p>
EOT;
$doc = new DOMDocument();
libxml_use_internal_errors(1);
$doc->loadHTML( "<body>$txt</body>", LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
$xpath = new DOMXpath( $doc );
$nodes = $xpath->query( "/*/*" );
foreach( $nodes as $key => $node ) echo $node->nodeName . PHP_EOL;
- Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- p
p
h1
p
p
figure
h1
p
p
h2
p
blockquote
p
preferences:
176.17 ms | 404 KiB | 227 Q