funnywheel
PHP & JS
- Регистрация
- 6 Авг 2010
- Сообщения
- 255
- Реакции
- 219
PHP:
<?php
function xmlReader ($pathFile,$code) {
$xml = simplexml_load_file($pathFile);
foreach ($xml->Currency as $item) {
if ($item['Id'] == $code) {
$result = $item->Rate;
break;
}
}
return $result;
}
function inbel($val) {
$localFilePath=$_SERVER['DOCUMENT_ROOT'].'/'.'Currency.xml';
$currentDate= date('m/d/Y');
$url = "http://www.nbrb.by/Services/XmlExRates.aspx?ondate=$currentDate";
$code = 145;
if (file_exists($localFilePath)) {
$xml = simplexml_load_file($localFilePath);
if ($xml){
$result=xmlReader($localFilePath,$code);
} else {
$result=xmlReader($url,$code);
}
}
return number_format($result*$val);
}
function inrur($val) {
$localFilePath=$_SERVER['DOCUMENT_ROOT'].'/'.'Currency.xml';
$currentDate= date('m/d/Y');
$url = "http://www.nbrb.by/Services/XmlExRates.aspx?ondate=$currentDate";
$code = 190;
if (file_exists($localFilePath)) {
$xml = simplexml_load_file($localFilePath);
if ($xml){
$result=xmlReader($localFilePath,$code);
} else {
$result=xmlReader($url,$code);
}
}
$currancyInBel= preg_replace("/\D/","",inbel($val));
return number_format($currancyInBel/$result);
}
function ineuro($val) {
$localFilePath = $_SERVER['DOCUMENT_ROOT'].'/'.'Currency.xml';
$currentDate = date('m/d/Y');
$url = "http://www.nbrb.by/Services/XmlExRates.aspx?ondate=$currentDate";
$code = 19;
if (file_exists($localFilePath)) {
$xml = simplexml_load_file($localFilePath);
if ($xml){
$result = xmlReader($localFilePath,$code);
} else {
$result = xmlReader($url,$code);
}
}
$currancyInBel = preg_replace("/\D/","",inbel($val));
return number_format($currancyInBel/$result);
}
?>
вывод суммы в валюте:
PHP:
echo inbel('1000');
echo inrur('1000');
echo ineuro('1000');
получение новой xml-ки с курсами уж сам настраивай