-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
31 lines (24 loc) · 961 Bytes
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
error_reporting(E_ALL);
$term = isset($_POST['term']) ? trim($_POST['term']) : '15 rue des champs';
$ch = curl_init("https://api-adresse.data.gouv.fr/search/?q=".urlencode($term));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$restmp = curl_exec($ch);
if(curl_error($ch)) {
$res= Array("error" => curl_error($ch));
var_dump($res);
}
curl_close($ch);
if(!empty($restmp)){
$jsonres=json_decode($restmp,TRUE);
$response=[];
foreach ($jsonres['features'] as $elem) {
$response[]=array('label' => $elem['properties']['label'],'address' => $elem['properties']['name'],'city' => $elem['properties']['city'],'postal_code' => $elem['properties']['postcode']);
}
echo json_encode($response);
}
exit;
?>