PHP file_get_contents issue

  • 1
  • Question
  • Updated 5 years ago
Hello:

I've successfully fetched and parsed the JSON station information returned from this function call:

file_get_contents("http://api.wunderground.com/api/keyre...");

I'm now trying to pass the parsed state (assigned to $closest_state) and city ($closest_city) to the observation URL:

file_get_contents("api.wunderground.com/api/keyremovedinposting/conditions/q/$closest_state/$closest_city.json");

The browser returns the following error:

Warning: file_get_contents(api.wunderground.com/api/keyremovedinposting/conditions/q/CO/Berthoud Pass.json) [function.file-get-contents]: failed to open stream: No such file or directory in C:\wamp\www\test\wunderground-tab.php on line 22

When I copy and paste the URL displayed in the error directly into the browser, the JSON is returned and visible in the browser window.

I'm thinking that the lack of forcing an http call is somehow involved in the problem but I'm not sure how to get around that.

Thanks in advanced!

Rick R.
Photo of Rick Rose

Rick Rose

  • 1 Post
  • 0 Reply Likes

Posted 5 years ago

  • 1
Photo of afelicioni

afelicioni

  • 227 Posts
  • 43 Reply Likes
It seems that a "http://" is missing from the beginning of the string passed to file_get_contents, so even the http wrapper is not triggered.