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
<?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, $tmp,PREG_SET_ORDER);
$rates=array();
foreach($tmp as $rate){
if(in_array($rate['1'],$codes)!==false){
$rates[]=array(
'title'=>$rate[3],
'quantity'=>$rate[2],
'rate'=>$rate[4],
'code'=>$rate[1],
);
}
}
print_r($rates);
?>