用 PHP 解析来自 Weatherbug 的天气数据

发布于 2024-10-06 10:52:46 字数 3892 浏览 8 评论 0原文

您好,

我正在尝试用 PHP 解析来自 Weatherbug 的 RSS 提要的实时天气数据。我以前曾将 simplexml_load_string() 与 NOAA 的天气数据一起使用,但我不知道如何从 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&amp;Units=0&amp;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&amp;Units=0&amp;stat=KNUI</aws:WebURL><aws:InputLocationURL>http://weather.weatherbug.com/VA/Heathsville-weather.html?ZCode=Z5546&amp;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="&amp;deg;F">33.1</aws:temp><aws:rain-today units="&quot;">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&amp;Units=0&amp;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&amp;Units=0&amp;stat=KNUI</link>

                     <pubDate>Tue, 07 Dec 2010 14:53:00 GMT</pubDate>
                     <description><![CDATA[

                             <img src="http://deskwx.weatherbug.com/images/Forecast/icons/cond007.gif" border="0" alt="Current Conditions"/>&nbsp;&nbsp;&nbsp;
                     <b>Sunny</b> <br />

                <b>Temperature:</b> 33.1 &deg;F&nbsp;&nbsp; 
               <br />
                <b>Wind Speed:</b> 14 mph WNW&nbsp;&nbsp;
            <br /> 
                <b>Gusts:</b> 28 mph WNW &nbsp;&nbsp;
                <b>Rain Today:</b> 0 &quot; &nbsp;&nbsp;
               <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>

我最需要的部分是 下的 。任何帮助将不胜感激!

Greetings,

I am trying to parse live weather data from Weatherbug's RSS feed in PHP. I had previously used simplexml_load_string() with NOAA's weather data but I cannot figure out how to output the data that I need from Weatherbug.

Here is the XML for current conditions:

    <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="http://deskwx.weatherbug.com/images/Forecast/icons/cond007.gif" border="0" alt="Current Conditions"/>   
                     <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>

The part that I most need is <description> under <item>. Any help would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城泪 2024-10-13 10:52:46

试试这个:

$description = (string)$simpleXml->channel->item->description;

Try this:

$description = (string)$simpleXml->channel->item->description;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文