/**
  * @return array|bool
  */
 public static function getCachedArray()
 {
     if (!empty(self::$arCurrency)) {
         return self::$arCurrency;
     }
     $file = @file_get_contents(dirname(__FILE__) . self::filePath);
     if ($file) {
         $temp = unserialize($file);
         if (is_array($temp) && !empty($temp)) {
             if ($temp['date'] > time() - 60 * 60 * 24) {
                 self::$arCurrency = $temp;
                 return self::$arCurrency;
             }
         }
     }
     $request = self::getXmlData();
     if ($request) {
         self::$arCurrency['date'] = time();
         foreach ($request->Valute as $currency) {
             self::$arCurrency['currencies'][(string) $currency->CharCode] = floatval(str_replace(',', '.', (string) $currency->Value));
         }
         if (!file_exists(dirname(dirname(__FILE__) . self::filePath))) {
             mkdir(dirname(dirname(__FILE__) . self::filePath), 0777, true);
         }
         file_put_contents(dirname(__FILE__) . self::filePath, serialize(self::$arCurrency));
         return self::$arCurrency;
     }
     return false;
 }
Пример #2
0
    $currencyList = array(
        'RUB',
        'EUR',
        'USD',
    );
    foreach ($currencyList as $currency) {?>
        <div class="js_currency currency <?php 
echo $currency == CentralBankRussianFederation::getCurrentCurrency() ? 'current' : '';
?>
" data-currency="<?php 
echo $currency;
?>
"><?php 
echo $currency;
?>
</div>
    <?}
?>
</div>
<?

$price = 123.53; // price in EUR

echo 'standard EUR: ' . $price . '<br>';
echo 'USD: ' . CentralBankRussianFederation::convert($price,'USD') . '<br>';
echo 'RUB: ' . CentralBankRussianFederation::convert($price,'RUB') . '<br>';
echo 'current ('.CentralBankRussianFederation::getCurrentCurrency().'): ' . CentralBankRussianFederation::convert($price) . '<br>';
echo 'current ('.CentralBankRussianFederation::getCurrentCurrency().'): ' . CentralBankRussianFederation::convertAndFormatted($price) . '<br>';
?>
</body>
</html>