- 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.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
- Array ( )
<?php
$html = ' Here is some text and also:
<figure class="class-one">
<img src="/example.jpg"
alt="example alt"
class="some-image-class">
<figcaption>example caption</figcaption>
</figure>
And another one (and many more):
<figure class="class-one some-other-class">
<img src="/example2.jpg"
alt="example2 alt">
</figure>';
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($html);
libxml_clear_errors();
$images = $dom->getElementsByTagName('img');
$figures = $dom->getElementsByTagName('figure');
$figures = array();
foreach ($figures as $figure) {
$figures['class'] = $figure->getAttribute('class');
}
print_r($figures);