我是PHP / XML的新手,我想添加Google的XML天气信息。并将该信息添加到我的.PHP页面。
我将使用此网址作为示例:https://www.google.com/ig/api?weather=12601&hl=en&referrer=googlecalendar
我在该URL获得的输出是:
<?xml version="1.0"?>
<xml_api_reply version="1">
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
<forecast_information>
<city data="Poughkeepsie, NY"/>
<postal_code data="12601"/>
<latitude_e6 data=""/>
<longitude_e6 data=""/>
<forecast_date data="2013-08-15"/>
<current_date_time data="1970-01-01 00:00:00 +0000"/>
<unit_system data="US"/>
</forecast_information>
<current_conditions>
<condition data="Partly Cloudy"/>
<temp_f data="78"/>
<temp_c data="26"/>
<humidity data="Humidity: 44%"/>
<icon data="/ig/images/weather/partly_cloudy.gif"/>
<wind_condition data="Wind: N at 2 mph"/>
</current_conditions>
<forecast_conditions>
<day_of_week data="Thu"/>
<low data="52"/>
<high data="81"/>
<icon data="/ig/images/weather/sunny.gif"/>
<condition data="Clear"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Fri"/>
<low data="52"/>
<high data="82"/>
<icon data="/ig/images/weather/partly_cloudy.gif"/>
<condition data="Partly Cloudy"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Sat"/>
<low data="57"/>
<high data="84"/>
<icon data="/ig/images/weather/partly_cloudy.gif"/>
<condition data="Partly Cloudy"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Sun"/>
<low data="59"/>
<high data="79"/>
<icon data="/ig/images/weather/cloudy.gif"/>
<condition data="Cloudy"/>
</forecast_conditions>
</weather>
</xml_api_reply>
我想提取以下信息。但我不知道怎么做,我想用min。如果可能的话代码量。
喜欢在.PHP页面中显示如下:
Currently: Partly Cloudy - 78*
Thu: Clear - Hi: 81* Lo: 52*
Fri: Partly Cloudy - Hi: 82* Lo: 52*
Sat: Partly Cloudy - Hi: 84* Lo: 57*
Sun: Cloudy - Hi: 79* Lo: 59*
感谢。
答案 0 :(得分:3)
使用SimpleXML
解析字符串并转换为对象。
$string = '...';
$xml = simplexml_load_string($string);
print_r($xml);