I just want to read out the google weather api xml with that code but it returns a 500. Any ideas why?
<?php
$url = "http://www.google.com/ig/api?weather=Moskva&hl=en";
$xml = simplexml_load_string(utf8_encode(file_get_contents($url)));
echo $xml->weather->current_conditions->temp_c->attributes()->data;
?>
Separate the lines out and introduce a try / catch block as follows :
try {
$url = "http://www.google.com/ig/api?weather=Moskva&hl=en";
$temp1 = file_get_contents($url);
$temp2 = utf8_encode($temp1);
$xml = simplexml_load_string($temp2);
echo $xml->weather->current_conditions->temp_c->attributes()->data;
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "
";
}
what happens then ?
Updated
Your response was due to the ip address your are coming from .... this was the response :
http://www.google.com/sorry/?continue=http://www.google.com/ig/api%3Fweather%3DMoskva%26hl%3Den
typing the response URL into a browser gives this :
Our systems have detected unusual traffic from your computer network. This page checks to see if it's really you sending the requests, and not a robot. Why did this happen?
IP address: 90.214.41.66 Time: 2012-01-06T21:35:24Z URL: http://www.google.com/ig/api?weather=Moskva&hl=en
Enter the URL in a browser and complete the CAPTCHA - should be sorted then
The problem is in your PHP configuration.
I just run the code and I get '2' as a result. No 500 error page.
It can definitely be a configuration. We have two servers, one local, and one develop / staging. Running only one line of code to get the RSS XML data, it works just fine on local, but gives 500 on staging. It's definitely a server configuration issue.