Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP解析Weatherbug中的天气数据_Php_Xml_Simplexml_Weather - Fatal编程技术网

用PHP解析Weatherbug中的天气数据

用PHP解析Weatherbug中的天气数据,php,xml,simplexml,weather,Php,Xml,Simplexml,Weather,您好 我试图用PHP解析Weatherbug的RSS提要中的实时天气数据。我以前在NOAA的天气数据中使用过simplexml_load_string(),但我不知道如何从Weatherbug输出我需要的数据 以下是适用于当前条件的XML: <rss version="2.0" xmlns:georss="http://www.georss.org/georss"> <channel> <title>Observations fro

您好

我试图用PHP解析Weatherbug的RSS提要中的实时天气数据。我以前在NOAA的天气数据中使用过simplexml_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&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>

美国马里兰州圣伊尼戈斯的观测结果
http://weather.weatherbug.com/MD/Saint Inigos weather.html?ZCode=Z5546&;单位=0&;stat=KNUI
世界上最大的气象网络的所有者Weatherbug现在以RSS的形式为其气象数据提供API。这将使it的热心用户能够构建自己的应用程序。
美国英语
2010年12月7日星期二格林威治标准时间16:00:00
60
http://weather.weatherbug.com/MD/Saint Inigos weather.html?ZCode=Z5546&;单位=0&;stat=KNUIhttp://weather.weatherbug.com/VA/Heathsville-weather.html?ZCode=Z5546&单位=0Sunny33.1
]]>
38.1488876342773 -76.4197235107422
2010年12月7日星期二16:00:36 GMT-Station1
我最需要的部分是
下的
。任何帮助都将不胜感激

试试这个:

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

工作很有魅力,谢谢你!你能给我一个这里发生的事情的简要分类吗?我对simplexml\u load\u stringWell相当陌生,
->channel
获取第一个channel节点,然后
->item
获取第一个item节点,依此类推。这仍将返回一个
simplexmlement
对象,但如果将其强制转换为字符串(即:
(string)
),它将返回节点的内部内容。