Skip to content

Commit

Permalink
Added rbi_inr_rates.php to get latest Reserve Bank of India (RBI) For…
Browse files Browse the repository at this point in the history
…ex rates in INR
  • Loading branch information
apmuthu committed Mar 15, 2018
1 parent e3cfcd0 commit 123e150
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pubip=`wget -qO- http://www.apmuthu.com/ip.php`
* `Bloomberg_Rates.php` - Get currency exchange rate from Bloomberg
* `fxratenet_rates.php` - Get currency exchange rate from fx-rate.net
* `XE/xe_xchg_rate.php` - Get all From/To exchange rates from [XE](http://www.xe.com)
* `rbi_inr_rates.php` - Get latest Reserve Bank of India (RBI) Forex rates in INR

### XML and HTML Parsers
* `ExtractOptions.php` - HTML select box options string to array
Expand Down
45 changes: 45 additions & 0 deletions rbi_inr_rates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/*
Purpose: Get the latest Reserve Bank of India Forex rates
Author : Ap.Muthu <[email protected]>
Release: 2018-03-15
Usage : echo print_r(get_rbi_rates(), true);
Output : Array([date] => 2018-03-15, [USD] => 64.9366, [EUR] => 80.5845, [GBP] => 90.8265, [YEN] => 0.6099);
Notes : Valid for USD, EUR, GBP, YEN to INR only
*/

function get_rbi_rates() {

$months=Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$xchg_rates = Array();
$url = 'https://rbi.org.in/scripts/BS_DisplayReferenceRate.aspx';
$contents = file_get_contents($url);
$parts = explode('US Dollar is ₹ ', $contents);
$part = explode(' ', $parts[1]);
$date['month']=str_pad(array_search($part[2], $months)+1, 2, '0', STR_PAD_LEFT);
$p1=explode(',',$part[3]);
$date['day']=$p1[0];
$p1=explode('.',$part[4]);
$date['year']=$p1[0];

$xchg_rates['date'] = $date['year'] . '-' . $date['month'] . '-' . $date['day'];

$xchg_rates['USD']=$part[0];
$parts = explode('US Dollar', $parts[1]);

$part = explode('1 EUR</td> <td align="center">', $parts[1]);
$part = explode('<', $part[1]);
$xchg_rates['EUR']=$part[0];

$part = explode('1 GBP</td> <td align="center">', $parts[1]);
$part = explode('<', $part[1]);
$xchg_rates['GBP']=$part[0];

$part = explode('100 YEN</td> <td align="center">', $parts[1]);
$part = explode('<', $part[1]);
$xchg_rates['YEN']=$part[0]/100.0;

return $xchg_rates;
}

?>

0 comments on commit 123e150

Please sign in to comment.