<?php
echo "<pre>";
$xml = '<?xml version="1.0"?><xml_api_reply version="1"><weather module_id="0" tab_id="0"><forecast_information><city data="Schriesheim, BW"/><postal_code data="Schriesheim,Germany"/><latitude_e6 data=""/><longitude_e6 data=""/><forecast_date data="2008-07-17"/><current_date_time data="2008-07-17 17:16:29 +0000"/><unit_system data="US"/></forecast_information><current_conditions><condition data=""/><temp_f data="64"/><temp_c data="18"/><humidity data="Humidity: 76%"/><icon data=""/><wind_condition data="Wind: SE at 1 mph"/></current_conditions><forecast_conditions><day_of_week data="Today"/><low data="55"/><high data="69"/><icon data="/images/weather/chance_of_rain.gif"/><condition data="Chance of Rain"/></forecast_conditions><forecast_conditions><day_of_week data="Fri"/><low data="55"/><high data="60"/><icon data="/images/weather/chance_of_rain.gif"/><condition data="Chance of Rain"/></forecast_conditions><forecast_conditions><day_of_week data="Sat"/><low data="53"/><high data="64"/><icon data="/images/weather/rain.gif"/><condition data="Rain"/></forecast_conditions><forecast_conditions><day_of_week data="Sun"/><low data="50"/><high data="64"/><icon data="/images/weather/chance_of_rain.gif"/><condition data="Chance of Rain"/></forecast_conditions></weather></xml_api_reply>';
$s = simplexml_load_string($xml);
foreach($s->weather->forecast_conditions as $day) {
$result['high'][(string)$day->day_of_week[0]{'data'}] = (string)$day->high[0]{'data'};
$result['low'][(string)$day->day_of_week[0]{'data'}] = (string)$day->low[0]{'data'};
$result['condition'][(string)$day->day_of_week[0]{'data'}] = (string)$day->condition[0]{'data'};
$result['icon'][(string)$day->day_of_week[0]{'data'}] = (string)$day->icon[0]{'data'};
}
var_dump($result);
echo "</pre>";
echo "<h1>Today</h1>\n";
echo "High: 69 <br />\n";
echo "Low: 55 <br />\n";
echo "Condition: Chance of Rain <br />\n";
echo "<h1>Fri</h1>\n";
echo "High: 77 <br />\n";
echo "Low: 55 <br />\n";
echo "Condition: Chance of Rain <br />\n";
echo "<h1>Sat</h1>\n";
echo "High: 64 <br />\n";
echo "Low: 53 <br />\n";
echo "Condition: Rain<br />\n";
echo "<h1>Sun</h1>\n";
echo "High: 64 <br />\n";
echo "Low: 50 <br />\n";
echo "Condition: Chance of Rain<hr />\n";
?>
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY
Open in new window