使用php从img src中提取更改图像


Pull changing image from img src with php

我试图使用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">

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;
}