- file_get_contents: documentation ( source)
- var_dump: documentation ( source)
- json_decode: documentation ( source)
- round: documentation ( source)
- ini_set: documentation ( source)
- error_reporting: documentation ( source)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
$json_string = file_get_contents("http://api.wunderground.com/api/Key/geolookup/conditions/lang:PL/q/Poland/Opole.json");
$parsed_json = json_decode($json_string);
$location = $parsed_json->{'location'}->{'city'};
$temp_c = floatval($parsed_json->{'current_observation'}->{'temp_c'});
$weather = $parsed_json->{'current_observation'}->{'weather'};
$feelslike_c = $parsed_json->{'current_observation'}->{'feelslike_c'};
$wind_kph = floatval($parsed_json->{'current_observation'}->{'wind_kph'});
if(1 == $temp_c) {
$stopnieSlownie = "stopień";
}
elseif( ($temp_c >= 2) && ($temp_c <= 4) ) {
$stopnieSlownie = "stopnie";
}
else {
$stopnieSlownie = "stopni";
}
if(1 == $wind_kph) {
$kilometrySlownie = "kilometr";
}
elseif( ($wind_kph >= 2) && ($wind_kph <= 4) ) {
$kilometrySlownie = "kilometry";
}
else {
$kilometrySlownie = "kilometrów";
}
var_dump($temp_c);
echo "To jest prognoza dla miejscowości ${location}:<br/>";
echo "Temperatura to " . round($temp_c) . " ${stopnieSlownie}, odczuwalne " . round($feelslike_c) . " ${stopnieSlownie}, jest ${weather} <br/>";
echo "Wiatr wieje z prędkością " . round($wind_kph) . " ${kilometrySlownie} na godzinę.\n";
?>
</body>
</html>