Google APIからGoogle天気をロードするこのphpスクリプトがあります。
<?php
//Weather Forecast icon and temperature from google weather API
$setYourLanguage = "en"; // Possibilities: "en" - english; "ru" - russian; "ka" - georgian;
//WEATHER, read google XML weather forecast
$URL = "http://www.google.com/ig/api?weather=".$myCity."&hl=".$setYourLanguage."";
$dataInISO = file_get_contents($URL);
$dataInUTF = mb_convert_encoding($dataInISO, "UTF-8", "ISO-8859-2"); //fix Google's API UTF-8 bug
$xml = simplexml_load_string($dataInUTF);
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$iconData = str_replace("/ig/images/weather/", "weather/", $current[0]->icon['data']);
$iconData = str_replace(".gif", ".png", $iconData);
?>
しかし、時々ページが読み込まれず、apache2 ログにエラーが表示されます:
[Thu Aug 23 12:04:16 2012] [error] [client ::1] PHP Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in /Library/WebServer/Documents/wordpress/wp-content/themes/directorypress/homepage-structure.php on line 23
[Thu Aug 23 12:04:16 2012] [error] [client ::1] PHP Warning: simplexml_load_string(): Unsupported API in /Library/WebServer/Documents/wordpress/wp-content/themes/directorypress/homepage-structure.php on line 23
[Thu Aug 23 12:04:16 2012] [error] [client ::1] PHP Warning: simplexml_load_string(): ^ in /Library/WebServer/Documents/wordpress/wp-content/themes/directorypress/homepage-structure.php on line 23
[Thu Aug 23 12:04:16 2012] [error] [client ::1] PHP Fatal error: Call to a member function xpath() on a non-object in /Library/WebServer/Documents/wordpress/wp-content/themes/directorypress/homepage-structure.php on line 25
[Thu Aug 23 12:05:57 2012] [error] [client ::1] What
なぜこれが起こっているのですか?私の理論では、URL に正しく接続できず、このように失敗します...しかし、ページの読み込みが停止するのはなぜですか? このエラーを回避する方法はありますか? ページを完全にロードできるようにしますか?