function Parse_Curs() {
$xml = simplexml_load_file( 'http://www.cbr.ru/scripts/XML_daily.asp', 'SimpleXMLElement', LIBXML_NOCDATA );
$curs_array[0] = array( 'CharCode' => 'RUB', 'Nominal' => '1', 'Name' => 'Российских рублей', 'Value' => '1' );
$i = 1;
foreach( $xml->Valute AS $el ) {
$curs_array_f = array();
$info = $el->CharCode . "|" . $el->Nominal . "|" . $el->Name . "|" . $el->Value;
$info = explode( '|', $info );
$exp_info = explode( ',', $info[3] );
$info[3] = $exp_info[0];
if ( count( $exp_info ) == 2 )
{
$info[3] .= '.' . $exp_info[1][0] . $exp_info[1][1] . $exp_info[1][2] . $exp_info[1][3];
}
$curs_array[$i] = array( 'CharCode' => $info[0], 'Nominal' => $info[1], 'Name' => $info[2], 'Value' => $info[3] );
$i++;
}
if ( count( $curs_array[1] ) > 1 ) {
return $curs_array;
} else {
return FALSE;
}
}
$ret = Parse_Curs();
$arr_code = array('USD','BYR','UAH');
foreach ( $ret AS $code => $info )
{
if ( $info['CharCode'] == 'RUB' )
{
$nazvanie_nujnoi_valytu = $info['Name'];
$value_nujnoi_valytu = $info['Value'] / $info['Nominal'];
//echo '[ ' . $info['CharCode'] . ' ]' .$nazvanie_nujnoi_valytu . ' : ' . $value_nujnoi_valytu . '<br>';
}
}
foreach ( $arr_code AS $code)
{
foreach ( $ret AS $kode => $info )
{
if ( $info['CharCode'] == $code )
{
$name_valytu = $info['Name'];
$value_valytu = $info['Value'] / $info['Nominal'];
//echo '[ ' . $info['CharCode'] . ' ]' .$name_valytu . ' : ' . $value_valytu . '<br>';
}
}
$kovnert = $value_nujnoi_valytu / $value_valytu;
$kovnert = number_format( $kovnert, 2, '.', '');
echo $kovnert . '<br>';
}