diff --git a/README.md b/README.md index d9ecc75..2ab901f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/rbi_inr_rates.php b/rbi_inr_rates.php new file mode 100644 index 0000000..13535b3 --- /dev/null +++ b/rbi_inr_rates.php @@ -0,0 +1,45 @@ + + 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