<?php
header("Content-Type: application/json; charset=utf-8");
if (!empty($_REQUEST['q'])){
$q = $_REQUEST['q'];
require_once('api-key.php');
$apiUrl = "http://api.openweathermap.org/data/2.5/weather?q=" . $q . "&lang=fr&units=metric&APPID=" . API_KEY;
$response = file_get_contents($apiUrl, False);
$data = json_decode($response, true); // $data = TABLEAU PHP
setLocale(LC_TIME,"fr_FR.UTF-8");
date_default_timezone_set("Europe/Paris");
$today = strftime('%A %d %B %y',time());
$hour = date('H:i:s');
// on prépare un tableau $json pour la réponse
$json = array("lieu" => $q,
"jour" => $today,
"heure"=> $hour,
"meteo"=> array());
$json['meteo']['main'] = $data['main'];
$json['meteo']['description'] = $data['weather'][0]['description'];
$json['meteo']['id'] = $data['weather'][0]['id'];
echo json_encode($json,JSON_PRETTY_PRINT);
}