1

I'm working on a wunderground weather intergration for a website and I would like to change/edit parts of the request URL for the API. I've tried a couple of solutions I found here on Stack overflow, but none have worked.

$state = 'NC';
$city = 'Boone';

$json_string = file_get_contents("https://api.wunderground.com/api/MY-API-KEY/geolookup/conditions/q/'.$state.'/'.$city.'.json");
$parsed_json = json_decode($json_string);
$location = $parsed_json->{'location'}->{'city'};
$temp_f = $parsed_json->{'current_observation'}->{'temp_f'};
echo "Current temperature in ${location} is: ${temp_f}\n";

I can't seem to figure it out. As you can see, I'm trying to make the state and city URL placements editable, (state & city).

It will output this:

Current temperature in [city name] is: [temp]

Any thoughts on how to edit the request URL?

2
  • 1
    Isn't it changing the variable $state and $city serve your needs ? Commented May 5, 2015 at 6:15
  • i think you mixed up " and ' in the query string, where you put your variables... Commented May 5, 2015 at 6:23

1 Answer 1

1

This part is wrong:

$json_string = file_get_contents("https://api.wunderground.com/api/MY-API-KEY/geolookup/conditions/q/'.$state.'/'.$city.'.json");

This should by like this:

$json_string = file_get_contents("https://api.wunderground.com/api/MY-API-KEY/geolookup/conditions/q/".$state."/".$city.".json");

or like this

$json_string = file_get_contents('https://api.wunderground.com/api/MY-API-KEY/geolookup/conditions/q/'.$state.'/'.$city.'.json');

See matching quotation marks and apostrophes.

Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant! I knew I was missing something. Thanks a million!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.