rogerthomas84 / ohexchange
OhExchange是一个PHP汇率库,利用欧洲中央银行的XML数据源。
1.0.0
2019-06-15 07:58 UTC
Requires
- php: >=7.0.0
- guzzlehttp/guzzle: ~6.0
This package is auto-updated.
Last update: 2024-09-15 20:00:15 UTC
README
OhExchange是一个简单的库,用于从欧洲中央银行检索汇率。
数据检索
<?php require 'vendor/autoload.php'; use OhExchange\OhExchangeException; use OhExchange\OhExchangeService; try { $models = OhExchangeService::getLatestRates(); foreach ($models as $model) { echo $model->date->format('Y-m-d') . PHP_EOL; foreach ($model->rates as $currency => $exchange) { echo ' ' . $currency . ' -> ' . $exchange . PHP_EOL; } // Persist this model, using the date as a unique identifier. } } catch (OhExchangeException $e) { echo 'Error:' . PHP_EOL; echo ' ' . $e; }
货币转换
<?php $model = new \OhExchange\OhExchangeDto(); // Should be retrieved from your database. $valueInUsd = $model->convertAmountFromTo(1, 'GBP', 'USD');