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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?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);
for ($i = 0; $i < 10; $i++) {
echo '-'.$i.'-';
}
echo dump(print_r($rates, 1));
die('18');
for ($i = 0; $i < count($rates['title'][1]); $i++) {
$rates[$i]['title'] = $rates['title'][1][$i];
$rates[$i]['quantity'] = $rates['quantity'][1][$i];
$rates[$i]['rate'] = $rates['rate'][1][$i];
$rates[$i]['code'] = $rates['code'][1][$i];
echo $i." - $rates[$i]['code']<br />";
}
echo '3-33<br />';
echo dump(print_r($rates, 1));
die('18');
foreach ($rates as $key => $value)
if (!in_array($value['code'], $codes))
unset($rates[$key]);
echo dump(print_r($rates, 1));
//echo $XMLrates;
?>