I searched several posts similar to this but could not find an answer. I am probably missing out something small.
I am trying to read JSON contents from a URL as shown by my code:
$uri = "http://worldweatheronline.com/feed/weather.ashx?q=schruns,austria&format=json&num_of_days=5&key=8f2d1ea151085304102710";
echo "URI: [$uri] <br/>";
$file = file_get_contents($uri);
$error = error_get_last();
echo $error['message'];
If I open the URL in a browser, I can see the JSON contents of it. But the above mentioned code does not work. $file
has a value of false
. The error message is:
file_get_contents(http://worldweatheronline.com/feed/weather.ashx?q=schruns,austria&format=json&num_of_days=5&key=8f2d1ea151085304102710) [function.file-get-contents]: failed to open stream: No such file or directory.
Any suggestions? NOTE: my allow_url_fopen
is set to 1
if it matters.
Edit: Here is the entire PHP file. http://pastebin.com/zCKEP9kG
Also, there is an fopen() in the code which opens an http file just fine.