Created
July 6, 2021 13:15
-
-
Save coonica/8ae4d0cb84af6ece62d6cb023a0089c6 to your computer and use it in GitHub Desktop.
php code for getting BYN to USD rate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$connection = curl_init(); | |
$currency = 'USD'; // parammode=2 – по буквенному коду валюты (ИСО 4217) | |
$date = '2021-07-01'; | |
$url = "https://www.nbrb.by/api/exrates/rates/$currency?parammode=2&ondate=$date"; | |
curl_setopt( $connection, CURLOPT_URL, $url ); | |
curl_setopt( $connection, CURLOPT_RETURNTRANSFER, 1 ); | |
curl_setopt( $connection, CURLOPT_TIMEOUT, 15 ); | |
$result = curl_exec( $connection ); | |
$response = json_decode( $result, true ); | |
if(!$response){ | |
echo '<p style="color:red">Error with curl for '.$url.': '. curl_error($connection).'</p>'; | |
} | |
else{ | |
echo (double) $response['Cur_OfficialRate']; | |
} | |
curl_close( $connection ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment