PHP code example of vasilevich / currencyconverter
1. Go to this page and download the library: Download vasilevich/currencyconverter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vasilevich / currencyconverter example snippets
vasilevich\currencyconverter\CurrencySourceBankOfEurope;
use vasilevich\currencyconverter\CurrencySourceBankOfIsrael;
use vasilevich\currencyconverter\CurrencySourceDenemarkNationalBank;
use vasilevich\currencyconverter\CurrencySourceFromSerialization;
$converter = new CurrencySourceBankOfEurope(); // use european bank
var_dump($converter->getCurrencyList()->convert("EUR", "USD", 1)); // -> 1 euro to usd through Europe bank
var_dump($converter->getCurrencyList()->convert("USD", "EUR", 1)); // -> 1 usd to euro through Europe bank
var_dump($converter->getCurrencyList()->convert("ILS", "EUR", 1)); // -> 1 ils to euro through Europe bank
var_dump($converter->getCurrencyList()->convert("EUR", "ILS", 1)); // -> 1 euro to ils through Europe bank
$converter = new CurrencySourceBankOfIsrael(); //use israeli bank
var_dump($converter->getCurrencyList()->convert("EUR", "USD", 1)); // -> 1 euro to usd through Israel Bank
var_dump($converter->getCurrencyList()->convert("USD", "EUR", 1)); // -> 1 usd to euro through Israel Bank
var_dump($converter->getCurrencyList()->convert("ILS", "EUR", 1)); // -> 1 ils to euro through Israel Bank
var_dump($converter->getCurrencyList()->convert("EUR", "ILS", 1)); // -> 1 euro to ils through Israel Bank
$converter = new CurrencySourceDenemarkNationalBank(); //use denemark national bank
var_dump($converter->getCurrencyList()->convert("EUR", "USD", 1)); // -> 1 euro to usd through Denemark national Bank
var_dump($converter->getCurrencyList()->convert("USD", "EUR", 1)); // -> 1 usd to euro through Denemark national Bank
var_dump($converter->getCurrencyList()->convert("ILS", "EUR", 1)); // -> 1 ils to euro through Denemark national Bank
var_dump($converter->getCurrencyList()->convert("EUR", "ILS", 1)); // -> 1 euro to ils through Denemark national Bank
$serializedConverter = $converter->serialize(); // convert the object to string, ready for caching/saving/transferring by your own logic
$unserializedConverter = new CurrencySourceFromSerialization($serializedConverter); //obtain the serialized converter from anywhere and deserialize the converter back into use
var_dump($unserializedConverter->getCurrencyList()->convert("ILS", "USD", 4)); //test converter
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.