Created
August 16, 2019 17:58
-
-
Save wzul/7b72a4284e4c2b3230c688cad72a6772 to your computer and use it in GitHub Desktop.
[PHP] BNM API Get Latest Exchange 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 | |
$host = 'https://api.bnm.gov.my/public/exchange-rate'; | |
$header = 'Accept: application/vnd.BNM.API.v1+json'; | |
$from_currency = 'USD'; | |
$data = array( | |
'session' => "0900", | |
); | |
$process = curl_init($host . '?' . http_build_query($data)); | |
curl_setopt($process, CURLOPT_HEADER, 0); | |
curl_setopt($process, CURLOPT_TIMEOUT, 5); | |
curl_setopt($process, CURLOPT_HTTPHEADER, array($header)); | |
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($process, CURLOPT_SSL_VERIFYHOST, 0); | |
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, 0); | |
$return = curl_exec($process); | |
curl_close($process); | |
$arr = json_decode($return, true); | |
foreach ($arr['data'] as $currency) { | |
if (in_array($from_currency, $currency)) { | |
$data = $currency; | |
break; | |
} | |
} | |
echo print_r($data, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment