Этот записать в current.json
{"current":{"date":"13.2.2018","value":58.02,"rate ":1},"previous":{"date":"12.2.2018","value":58.17, "rate":1}}
Код current.php должен быть таким:
<?
$day = date('w');
if($day && $day<>6) { //если не воскресенье и суббота
$dir = dirname(__FILE__);
chdir($dir);
$currency = json_decode(file_get_contents('current.json'));
libxml_use_internal_errors();
$xml = simplexml_load_file('http://www.cbr.ru/scripts/XML_daily.asp?date_req='.date('d/m/Y'));
$date = date('j.n.Y', strtotime($xml->attributes()->Date));
foreach ($xml->children() as $child) {
if($child->NumCode==840) {
$usd = round((float)str_replace(',', '.', $child->Value), 2);
break;
}
}
if($rate = $usd - $currency->current->value) $rate = $rate < 0 ? 1 : 2;
$currency->previous = clone $currency->current;
$currency->current->date = $date;
$currency->current->value = $usd;
$currency->current->rate = $rate;
chmod($dir, 0777);
file_put_contents('current.json', json_encode($currency));
chmod($dir, 0700);
}
?>
В js коде вывода изменения в структуре массивов:
$('.'+k).html("$ " + o.value + ' <b class=' + ['','down','up'][o.rate] +'>' + ['','▼','▲'][o.rate] +'</b>').attr("title", o.date)