I tried to follow some questions here about preg_match and DOM, but everything just flew over my head.
I have a string like this:
$string = '<td class="borderClass" width="225" style="border-width: 0 1px 0 0;" valign="top">
<div style="text-align: center;">
<a href="http://myanimelist.net/anime/10800/Chihayafuru/pic&pid=35749">
<img src="http://cdn.myanimelist.net/images/anime/3/35749.jpg" alt="Chihayafuru" align="center">
</a>
</div>';
I'm now trying to get the image src attribute value from it. I tried using this code, but I can't figure out what I'm doing wrong.
$doc = new DOMDocument();
$dom->loadXML( $string );
$imgs = $dom->query("//img");
for ($i=0; $i < $imgs->length; $i++) {
$img = $imgs->item($i);
$src = $img->getAttribute("src");
}
$scraped_img = $src;
How may I get the image src attribute from this using php?