32 lines
678 B
PHP
32 lines
678 B
PHP
<?php
|
|
require 'config.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
if (!isset($_GET['name'])) {
|
|
echo json_encode([]);
|
|
exit;
|
|
}
|
|
|
|
$name = $_GET['name'];
|
|
$url = 'https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords=' . urlencode($name) . '&apikey=' . $alphaApiKey;
|
|
|
|
$response = file_get_contents($url);
|
|
if (!$response) {
|
|
echo json_encode([]);
|
|
exit;
|
|
}
|
|
|
|
$data = json_decode($response, true);
|
|
$matches = $data['bestMatches'] ?? [];
|
|
|
|
$result = [];
|
|
foreach ($matches as $match) {
|
|
$result[] = [
|
|
'symbol' => $match['1. symbol'],
|
|
'name' => $match['2. name'],
|
|
'region' => $match['4. region']
|
|
];
|
|
}
|
|
|
|
echo json_encode($result);
|