Created
December 30, 2011 11:14
-
-
Save anonymous/1539364 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'] . "> "; | |
print "<br><br>"; | |
print " " . $current[0]->condition['data'] . " "; | |
print " " . $current[0]->temp_f['data'] . " В°F"; | |
print "<br>"; | |
print " " . $current[0]->wind_condition['data']; | |
print "<br>"; | |
print " " . $current[0]->humidity['data']; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment