Solucio temps

De wikiserver
La revisió el 14:24, 30 març 2015 per Jnoguera (Discussió | contribucions) (Es crea la pàgina amb «<source lang="html"> <!DOCTYPE html> <meta charset="UTF-8"> <form method="get" action="tiempo.php"> <label> Ciudad </label> <input type = "text" nam…».)
(dif) ← Versió més antiga | Versió actual (dif) | Versió més nova → (dif)
Dreceres ràpides: navegació, cerca
<!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>";  
?>