Parse weather data from Weatherbug in PHP(用PHP解析WeatherBug中的天气数据)
本文介绍了用PHP解析WeatherBug中的天气数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问候,
我正在尝试用PHP解析WeatherBug的RSS提要中的实时天气数据。我以前对NOAA的天气数据使用了implexml_Load_String(),但我想不出如何从WeatherBug输出我需要的数据。
以下是当前条件的XML:
<rss version="2.0" xmlns:georss="http://www.georss.org/georss">
<channel>
<title>Observations from Saint Inigoes, MD - USA</title>
<link>http://weather.weatherbug.com/MD/Saint Inigoes-weather.html?ZCode=Z5546&Units=0&stat=KNUI</link>
<description>Weatherbug, the owner of the world's largest weather network is now providing an API to it's weather data in the form of RSS. This will enable it's enthusiastic users to build their own applications.</description>
<language>en-us</language>
<lastBuildDate>Tue, 07 Dec 2010 16:00:00 GMT</lastBuildDate>
<ttl>60</ttl>
<aws:weather xmlns:aws="http://www.aws.com/aws"><aws:api version="2.0" /><aws:WebURL>http://weather.weatherbug.com/MD/Saint Inigoes-weather.html?ZCode=Z5546&Units=0&stat=KNUI</aws:WebURL><aws:InputLocationURL>http://weather.weatherbug.com/VA/Heathsville-weather.html?ZCode=Z5546&Units=0</aws:InputLocationURL><aws:station requestedID="" id="KNUI" name="Webster Field, Naval Electronic Syste" city="Saint Inigoes" state=" MD" zipcode="20684" country="USA" latitude="38.1488876342773" longitude="-76.4197235107422" /><aws:current-condition icon="http://deskwx.weatherbug.com/images/Forecast/icons/cond007.gif">Sunny</aws:current-condition><aws:temp units="&deg;F">33.1</aws:temp><aws:rain-today units=""">0</aws:rain-today><aws:wind-speed units="mph">14</aws:wind-speed><aws:wind-direction>WNW</aws:wind-direction><aws:gust-speed units="mph">28</aws:gust-speed><aws:gust-direction>WNW</aws:gust-direction></aws:weather>
<image>
<title>Local Weather from WeatherBug</title>
<width>142</width>
<height>18</height>
<link>http://weather.weatherbug.com/MD/Saint Inigoes-weather.html?ZCode=Z5546&Units=0&stat=KNUI</link>
<url>http://www.weatherbug.com/aws/imagesHmPg0604/img_wxbug_logo_whiteBG.gif</url>
</image>
<item>
<title>Live Conditions from Saint Inigoes, MD - USA</title>
<link>http://weather.weatherbug.com/MD/Saint Inigoes-weather.html?ZCode=Z5546&Units=0&stat=KNUI</link>
<pubDate>Tue, 07 Dec 2010 14:53:00 GMT</pubDate>
<description><![CDATA[
<img src="aHR0cDovL2Rlc2t3eC53ZWF0aGVyYnVnLmNvbS9pbWFnZXMvRm9yZWNhc3QvaWNvbnMvY29uZDAwNy5naWY=" border="0" alt="Q3VycmVudCBDb25kaXRpb25z"/>
<b>Sunny</b> <br />
<b>Temperature:</b> 33.1 °F
<br />
<b>Wind Speed:</b> 14 mph WNW
<br />
<b>Gusts:</b> 28 mph WNW
<b>Rain Today:</b> 0 "
<br />
]]></description>
<georss:point>38.1488876342773 -76.4197235107422</georss:point>
<guid isPermaLink="false">Tue, 07 Dec 2010 16:00:36 GMT-Station1</guid>
</item>
</channel>
</rss>
我最需要的部分是<item>
下的<description>
。如有任何帮助,将不胜感激!
推荐答案
试试:
$description = (string)$simpleXml->channel->item->description;
这篇关于用PHP解析WeatherBug中的天气数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:用PHP解析WeatherBug中的天气数据


猜你喜欢
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01