Skip to content

Instantly share code, notes, and snippets.

Created December 30, 2011 11:14
Show Gist options
  • Save anonymous/1539364 to your computer and use it in GitHub Desktop.
Save anonymous/1539364 to your computer and use it in GitHub Desktop.
<?php
header('Content-Type: text/html; charset=utf-8');
$xml;
function sxe($url) {
$xml = file_get_contents($url);
foreach ($http_response_header as $header) {
if (preg_match('#^Content-Type: text/xml; charset=(.*)#i', $header, $m)) {
switch (strtolower($m[1])) {
case 'utf-8':
// do nothing
break;
case 'iso-8859-1':
$xml = utf8_encode($xml);
break;
default:
$xml = iconv($m[1], 'utf-8', $xml);
}
break;
}
}
return simplexml_load_file($xml);
}
$url = 'http://www.google.com/ig/api?weather=moscow&hl=ru';
sxe($url);
var_dump($xml);
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
print "<img src=http://www.google.com" . $current[0]->icon['data'] . ">&nbsp;";
print "<br><br>";
print "&nbsp;" . $current[0]->condition['data'] . "&nbsp;";
print "&nbsp;" . $current[0]->temp_f['data'] . "&nbsp;В°F";
print "<br>";
print "&nbsp;" . $current[0]->wind_condition['data'];
print "<br>";
print "&nbsp;" . $current[0]->humidity['data'];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment