Solucio temps
De wikiserver
La revisió el 14:24, 30 març 2015 per Jnoguera (Discussió | contribucions)
<!DOCTYPE html>
<meta charset="UTF-8">
<form method="get" action="tiempo.php">
<label>
Ciudad
</label>
<input type = "text" name="c">
<input type = "submit" value="Mostrar el Tiempo">
</form>
//arxiu temps
<?php
if($_GET["c"]==null) die();
$html = file_get_contents("http://api.openweathermap.org/data/2.5/weather?q=".$_GET["c"]);
$json = json_decode($html);
$ciudad = $json->name;
$lat = $json->coord->lat;
$lon = $json->coord->lon;
$temp = $json->main->temp;
$tempmax = $json->main->temp_max;
$tempmin = $json->main->temp_min;
$presion = $json->main->pressure;
$humedad = $json->main->humidity;
$vel_viento = $json->main->temp;
$estado_cielo = $json->weather[0]->main;
$descripcion = $json->weather[0]->description;
echo "<h3>Ciudad: ".$ciudad." [lat = ".$lat. ", lon = ".$lon. " ]</h3>";
echo "<b>Estado del cielo: </b>".$estado_cielo."<br>";
echo "<b>Descripción: </b>".$descripcion."<br>";
echo "<br>";
echo "<b>Temperatura: </b>".$temp." K [Máx: ".$tempmax."K, Mín: ".$tempmin."K]<br>";
echo "<b>Presión: </b>".$presion."<br>";
echo "<b>Humedad: </b>".$humedad."<br>";
echo "<br><br><br><br><br>";
?>
Exemple de json que retorna
{"coord":{"lon":-0.9,"lat":38.06},"sys":{"message":0.0991,"country":"Spain","sunrise":1392619830,"sunset":1392659075},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"base":"cmc stations","main":{"temp":288.15,"pressure":1012,"humidity":72,"temp_min":288.15,"temp_max":288.15},"wind":{"speed":5.1,"deg":60},"rain":{"3h":0},"clouds":{"all":20},"dt":1392661800,"id":2513076,"name":"Bigastro","cod":200}