PHP code example of plugowski / currency_converter

1. Go to this page and download the library: Download plugowski/currency_converter 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/ */

    

plugowski / currency_converter example snippets



ey = new CurrencyConverter\Money\Money(1, new CurrencyConverter\Currency\Currency('EUR'));

$rateCollection =  new \CurrencyConverter\Exchange\RateCollection();
$rateCollection->add(new \CurrencyConverter\Exchange\Rate('EUR', 4.2636));
$rateCollection->add(new \CurrencyConverter\Exchange\Rate('PLN', 1.0000));

$converter = new CurrencyConverter\Converter($rateCollection);
$converted = $converter->exchange($money, new CurrencyConverter\Currency\Currency('PLN'));

// how many PLN are in 1 EUR
echo $converted->getValue();

$money = Money::EUR(1);


$exchangeService = new CurrencyConverter\Exchange\Service(new CurrencyConverter\Exchange\Repository\NBPRatesRepository());
$converted = $exchangeService->convert(CurrencyConverter\Money\Money::EUR(4), new CurrencyConverter\Currency('PLN'));


$formatter = \CurrencyConverter\Money\FormatterFactory::create('pl_PL');
$formatter->setMoney(\CurrencyConverter\Money\Money::PLN(20.99));

echo $formatter->spell(); // will return: dwadzieścia złotych dziewięćdziesiąt dziewięć groszy