Google Väder API Med PHP

Tänkte tipsa er om Google Väder API som är mycket enkelt att använda, slängde ihop lite kod i PHP som plockar ut nuvarande prognos.

$url = <a href="http://www.google.se/ig/api?weather=paris">http://www.google.se/ig/api?weather=paris</a>;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close($ch);

$xml = new SimpleXMLElement(utf8_encode($html));
$return_array = array();

$weather_array['prognos_info']['city'] = $xml->weather->forecast_information->city['data'];
$weather_array['prognos_info']['zip'] = $xml->weather->forecast_information->postal_code['data'];
$weather_array['prognos_info']['date'] = $xml->weather->forecast_information->forecast_date['data'];
$weather_array['prognos_info']['date_time'] = $xml->weather->forecast_information->current_date_time['data'];
$weather_array['current_cond']['condition'] = $xml->weather->current_conditions->condition['data'];
$weather_array['current_cond']['temp_f'] = $xml->weather->current_conditions->temp_f['data'];
$weather_array['current_cond']['temp_c'] = $xml->weather->current_conditions->temp_c['data'];
$weather_array['current_cond']['humidity'] = $xml->weather->current_conditions->humidity['data'];
$weather_array['current_cond']['icon'] = 'http://www.google.com' . $xml->weather->current_conditions->icon['data'];
$weather_array['current_cond']['wind'] = $xml->weather->current_conditions->wind_condition['data'];
 

Nu när man håller på med resedomäner så är det alltid användbart

Det här inlägget postades i PHP. Bokmärk permalänken.

En kommentar till Google Väder API Med PHP

  1. Fredrik skriver:

    Bra, då slipper jag lägga någon energi på detta :)

Kommentera

E-postadressen publiceras inte. Obligatoriska fält är märkta *

*

Följande HTML-taggar och attribut är tillåtna: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Comments links could be nofollow free.