How to use icons for my current contitions with php ?

  • 1
  • Question
  • Updated 6 years ago
Hello everybody
because am very new with wunder weather API i have a question .

Until now i have this script :

$json_string = file_get_contents("http://api.wunderground.com/api/1ac33...");
$parsed_json = json_decode($json_string);
$location = $parsed_json->{'location'}->{'city'};
$icon = $parsed_json->{'current_observation'}->{'icon'};
$temp_c = $parsed_json->{'current_observation'}->{'temp_c'};
echo " Weather now : ${temp_c} C $icon \n";

My question is, how can i show an icon for my current conditions ?
I know that here are the icon sets http://www.wunderground.com/weather/a... but i dont know how to use them into my code !

Can you please help me with a small sample of php-code using icons ?

Thanks in advance
Photo of Weatherps

Weatherps

  • 4 Posts
  • 0 Reply Likes

Posted 6 years ago

  • 1
Photo of afelicioni

afelicioni

  • 227 Posts
  • 43 Reply Likes
Looks like a simple question (but I may have misunderstood it) and a very simple answer can be smoething like the following, if using HTML for output


echo " Weather now : ${temp_c} C <img src='http://icons.wxug.com/i/c/a/$icon.gif' /> \n";

of course, don't care about the style, just try to play with $icon; maybe using printf() could be written better and easier to read

Were you really looking for this?
Photo of Weatherps

Weatherps

  • 4 Posts
  • 0 Reply Likes
oh yeh, thanks so much afelicioni ;)