-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrbi_inr_rates.php
45 lines (36 loc) · 1.46 KB
/
rbi_inr_rates.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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;
}
?>