Skip to content

Instantly share code, notes, and snippets.

@coonica
Created July 6, 2021 13:15
Show Gist options
  • Save coonica/8ae4d0cb84af6ece62d6cb023a0089c6 to your computer and use it in GitHub Desktop.
Save coonica/8ae4d0cb84af6ece62d6cb023a0089c6 to your computer and use it in GitHub Desktop.
php code for getting BYN to USD rate
<?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