用php从img src中拉出图像

时间:2013-03-09 14:03:58

标签: php image

我正在尝试使用PHP从weather.com(当前条件图像)中提取图像,但我无法弄清楚如何这样做,因为天气时图像会发生变化,所以我无法链接直接到它。有没有办法从标签中提取图像,所以当图像源发生变化时,PHP会获得新的图像?

这是我希望PHP从中获取的标签:

<img class="wx-weather-icon" src="http://s.imwx.com/v.20120328.084208//img/wxicon/120/32.png" height="93" width="93" alt="Sunny">

1 个答案:

答案 0 :(得分:1)

SimpleHTMLDOM

可能是您最好的选择,然后您可以继续执行以下操作

// Create DOM from URL or file
$html = file_get_html('http://www.weather.com/');

foreach($html->find('img[class=wx-weather-icon]') as $element) {
   echo $element->src;
}
相关问题