I want show weather information from xml to this URL: http://www.google.com/ig/api?weather=roma&hl=it using this script:
<?
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=roma&hl=it');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
?>
<html>
<head>
<title>Google Weather API</title>
</head>
<body>
<h1><?= print $information[0]->city['data']; ?></h1>
<h2>Today's weather</h2>
<div class="weather">
<img src="<?= 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
<span class="condition">
<?= $current[0]->temp_f['data'] ?>° F,
<?= $current[0]->condition['data'] ?>
</span>
</div>
<h2>Forecast</h2>
<? foreach ($forecast_list as $forecast) : ?>
<div class="weather">
<img src="<?= 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
<div><?= $forecast->day_of_week['data']; ?></div>
<span class="condition">
<?= $forecast->low['data'] ?>° F - <?= $forecast->high['data'] ?>° F,
<?= $forecast->condition['data'] ?>
</span>
</div>
<? endforeach ?>
</body>
</html>
But the script does not show any output, if I delete the language specification (&hl=it) from simplexml_load_file’s parameters, it works.
Error_log_php Output:
[24-Jun-2011 11:12:53] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: http://www.google.com/ig/api?weather=roma&hl=it:1: parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0xE0 0x3A 0x20 0x35 in /home/site/public_html/test.php on line 2
[24-Jun-2011 11:12:53] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: ialmente nuvoloso"/><temp_f data="81"/><temp_c data="27"/><humidity data="Umidit in /home/site/public_html/test.php on line 2
[24-Jun-2011 11:12:53] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]:^ in /home/site/public_html/test.php on line 2
[24-Jun-2011 11:12:53] PHP Fatal error: Call to a member function xpath() on a non-object in /home/site/public_html/test.php on line 3
user this code because external xml dont read from your site so use this curl code