2022-02-19 17:40:56 -03:00
|
|
|
<?php
|
2022-03-01 13:28:37 -03:00
|
|
|
function currency_results($query, $response)
|
2022-02-19 17:40:56 -03:00
|
|
|
{
|
2022-02-25 06:42:32 -03:00
|
|
|
require "config.php";
|
|
|
|
require_once "misc/tools.php";
|
2022-02-19 17:40:56 -03:00
|
|
|
|
|
|
|
$split_query = explode(" ", $query);
|
|
|
|
|
2022-03-01 13:28:37 -03:00
|
|
|
$base_currency = strtoupper($split_query[1]);
|
|
|
|
$currency_to_convert = strtoupper($split_query[3]);
|
|
|
|
$amount_to_convert = floatval($split_query[0]);
|
|
|
|
|
|
|
|
$json_response = json_decode($response, true);
|
2022-02-19 17:40:56 -03:00
|
|
|
|
2022-03-01 13:28:37 -03:00
|
|
|
$rates = $json_response["rates"];
|
2022-02-19 17:40:56 -03:00
|
|
|
|
2022-03-01 13:28:37 -03:00
|
|
|
if (array_key_exists($base_currency, $rates) && array_key_exists($currency_to_convert, $rates))
|
|
|
|
{
|
|
|
|
$base_currency_response = $rates[$base_currency];
|
|
|
|
$currency_to_convert_response = $rates[$currency_to_convert];
|
2022-02-19 17:40:56 -03:00
|
|
|
|
2022-03-01 13:28:37 -03:00
|
|
|
$conversion_result = ($currency_to_convert_response / $base_currency_response) * $amount_to_convert;
|
2022-02-19 17:40:56 -03:00
|
|
|
|
2022-03-03 06:32:46 -03:00
|
|
|
$formatted_response = "$amount_to_convert $base_currency = $conversion_result $currency_to_convert";
|
|
|
|
$source = "https://moneyconvert.net/";
|
|
|
|
return array(
|
|
|
|
"special_response" => array(
|
|
|
|
"response" => $formatted_response,
|
|
|
|
"source" => $source
|
|
|
|
)
|
|
|
|
);
|
2022-03-01 13:28:37 -03:00
|
|
|
}
|
2022-02-19 17:40:56 -03:00
|
|
|
}
|
|
|
|
?>
|