PHP and Weather Alerts

  • 1
  • Question
  • Updated 5 years ago
When trying to pull alerts, I am not getting any error but it is not returning anything. Here is the code I'm using:

$json_string = file_get_contents("");
$parsed_json = json_decode($json_string);
$location = $parsed_json->{'location'}->{'city'};
$wind_dir = $parsed_json->{'current_observation'}->{'wind_dir'};
$wind_mph = $parsed_json->{'current_observation'}->{'wind_mph'};
$wind_gust_mph = $parsed_json->{'current_observation'}->{'wind_gust_mph'};
$temp = $parsed_json->{'current_observation'}->{'temp_f'};
$feelslike = $parsed_json->{'current_observation'}->{'feelslike_f'};
// echo "Current temperature in ${location} is: ${temp_f}\n";
$json_stringalert = file_get_contents("");
$parsed_jsonalert = json_decode($json_stringalert);
$description = $parsed_jsonalert->{'alerts'}->{'description'};
$date = $parsed_jsonalert->{'alerts'}->{'date'};
$expires = $parsed_jsonalert->{'alerts'}->{'expires'};

I then echo the alert variables later in the html body. However, they are just blank (even when on, it showed an active alert for Fairview Heights)

Any ideas?
Photo of rlrandolph


  • 1 Post
  • 0 Reply Likes
  • frustrated

Posted 5 years ago

  • 1
Photo of afelicioni


  • 227 Posts
  • 42 Reply Likes
Please mind that alerts feature (as the "s" in plural suggests) returns a numeric array structure, so you should cycle it with a for, foreach or something