php set_time_limit XMLrates file_get_contents http www cbr ru scripts

 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
<?php
set_time_limit(1);
$XMLrates = file_get_contents('http://www.cbr.ru/scripts/XML_daily.asp?date_req='.date('d/m/Y'));
$codes = Array('USD', 'EUR');
$XMLrates = str_replace(Array("\t", "\r", "\n"), '', $XMLrates);
$rates = Array();
$pattern = '#<CharCode>(.*?)</CharCode>'.
'<Nominal>(.*?)</Nominal>'.
'<Name>(.*?)</Name>'.
'<Value>(.*?)</Value>#';
preg_match_all($pattern, $XMLrates, $rates_pre);
$rates = Array();
for ($i = 0; $i < count($rates_pre[0]); $i++) {
if (in_array($rates_pre[1][$i], $codes)) {
$rates[$i]['title'] = $rates_pre[3][$i];
$rates[$i]['quantity'] = $rates_pre[2][$i];
$rates[$i]['rate'] = $rates_pre[4][$i];
$rates[$i]['code'] = $rates_pre[1][$i];
}
}
echo dump(print_r($rates, 1));
//echo $XMLrates;
?>