Get weather information

Change the city and country below, this uses data from http://www.openweathermap.org/

<?php
$city="Dundee";
$country="UK"; //Two digit country code
$url="http://api.openweathermap.org/data/2.5/weather?q=".$city.",".$country."&units=metric&cnt=7&lang=en";
$json=file_get_contents($url);
$data=json_decode($json,true);
//Get current Temperature in Celsius
echo "Temperature : " . $data['main']['temp']." c<br>";
//Get weather conditions
echo "Conditions : " . $data['weather'][0]['main']."<br>";
//Get cloud percentage
echo "Cloud percentage : " . $data['clouds']['all']." %<br>";
//Get wind speed
echo "Wind speed : " . $data['wind']['speed']." mph<br>";
?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*