I found this code online to pull all tags from a url
<?php
$url="http://www.foo.com/xxxxxx";
$html = file_get_contents($url);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$tags = $doc->getElementsByTagName('img');
foreach ($tags as $tag) {
echo '<img src="' . $tag->getAttribute('src') . '"></img>';
}
?>
and it works fine now i am trying to adapt it to find specific tags based on class.
<?php
$url="http://www.foo.com/xxxxxx";
$html = file_get_contents($url);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$tags = $doc->getElementsByClassName('bar');
foreach ($tags as $tag) {
echo '<div>' . $tag->getAttribute('div') . '</div>';
}
?>
but I keep getting this
Fatal error: Call to undefined method DOMDocument::getElementsByClassName() in /index.php on line 9
what am i doing wrong