43 lines
1018 B
PHP
43 lines
1018 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Dadata;
|
||
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
|
||
|
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
|
||
|
|
|
||
|
|
if (isset($_POST['searchTerm'])) {
|
||
|
|
$search = $_POST['searchTerm'];// Search text
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isset($_POST['page'])) {
|
||
|
|
$page = $_POST['page'];
|
||
|
|
}
|
||
|
|
$options = array(
|
||
|
|
'http' => array(
|
||
|
|
'method' => 'POST',
|
||
|
|
'header' => array(
|
||
|
|
'Content-type: application/json',
|
||
|
|
'Authorization: Token ' . $dadataToken,
|
||
|
|
'X-Secret: ' . $dadataSecret,
|
||
|
|
),
|
||
|
|
'content' => json_encode(array(
|
||
|
|
$search
|
||
|
|
)),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
$context = stream_context_create($options);
|
||
|
|
|
||
|
|
$results = file_get_contents("https://cleaner.dadata.ru/api/v1/clean/address", false, $context);
|
||
|
|
|
||
|
|
|
||
|
|
$response = [];
|
||
|
|
$response['items'] = array();
|
||
|
|
// Read Data
|
||
|
|
foreach (json_decode($results) as $k => $result) {
|
||
|
|
$response['items'][] = array(
|
||
|
|
"id" => (string) $k,
|
||
|
|
"text" => $result->result
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
echo json_encode($response);
|
||
|
|
exit();
|