PHP code example of fallenangelbg / bgncurrencytool

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

    

fallenangelbg / bgncurrencytool example snippets



use Fallenangelbg\BGNCurrencyTool\currencyConvertor;
use Fallenangelbg\BGNCurrencyTool\currencyReadExternal;

$BNBPage = "https://www.bnb.bg/Statistics/StExternalSector/StExchangeRates/StERForeignCurrencies/index.htm?download=xml&amp;search=&amp;lang=BG";
$currencyData = array();
try {
    $currencyData = (new currencyReadExternal($BNBPage))->readCurrency();
}
catch (Exception $e) {
    die("Error occurred!" . $e);
}
$sumToBeConverted = 100000;
$sumCurrency = "USD";

$currencyConverterTool = new currencyConvertor($usedCurrencies, $currencyData);
try {
    $convertToLev = $currencyConverterTool->convertToLev($sumToBeConverted, $sumCurrency);
    var_dump($convertToLev);
}
catch (Exception $e) {
    die($e);
}
 
array(2) {
  ["error"]=>
  string(0) ""
  ["sum"]=>
  float(177947.98)
}


use Fallenangelbg\BGNCurrencyTool\currencyConvertor;
use Fallenangelbg\BGNCurrencyTool\currencyReadExternal;

$usedCurrencies = array(
  "BGN" => "BGN",
  "USD" => "USD",
  "EUR" => "EUR",
);

$currencyData = array();
try {
    $currencyData = (new currencyReadExternal($BNBPage))->readCurrency();
}
catch (Exception $e) {
    die("Error occurred!" . $e);
}
$sumToBeConverted = 100000;
$sumCurrency = "USD";

$currencyConverterTool = new currencyConvertor($usedCurrencies, $currencyData);

try {
    $convertedCurrencies = $currencyConverterTool->currencyCalculate($convertToLev['sum']);
    var_dump($convertedCurrencies);
}
catch (Exception $e) {
    die($e);
}

array(3) {
  ["BGN"]=>
  float(177947.98)
  ["USD"]=>
  float(100000)
  ["EUR"]=>
  float(90983.02)
}


use Fallenangelbg\BGNCurrencyTool\currencyReadExternal;

$BNBPage = "https://www.bnb.bg/Statistics/StExternalSector/StExchangeRates/StERForeignCurrencies/index.htm?download=xml&amp;search=&amp;lang=BG";
$currencyData = (new currencyReadExternal($BNBPage))->readCurrency();
// Result:
Array
(
    ['EUR'] => Array
        (
            ['name'] => 'Euro'
            ['code'] => 'EUR'
            ['quantity'] => 1
            ['value'] => 0.51129
        )

    ['BGN'] => Array
        (
            ['name'] => 'Bulgarian Lev'
            ['code'] => 'BGN'
            ['quantity'] => 1
            ['value'] => 1
        )

    ['AUD'] => Array
        (
            ['name'] => 'Австралийски долар'
            ['code'] => 'AUD'
            ['quantity'] => 1
            ['value'] => 0.769752
        )

    ['BRL'] => Array
        (
            ['name'] => 'Бразилски реал'
            ['code'] => 'BRL'
            ['quantity'] => 10
            ['value'] => 2.88057
        )
        /* ... */
    ['USD'] => Array
        (
            ['name'] => 'Щатски долар'
            ['code'] => 'USD'
            ['quantity'] => 1
            ['value'] => 0.565029
        )

    ['ZAR'] => Array
        (
            ['name'] => 'Южноафрикански ранд'
            ['code'] => 'ZAR'
            ['quantity'] => 10
            ['value'] => 8.45094
        )        
)

$returnArray["BGN"]['name'] = "Bulgarian Lev";
$returnArray["BGN"]['code'] = "BGN";
$returnArray["BGN"]['quantity'] = 1;
$returnArray["BGN"]['value'] = 1;
 
https://www.bnb.bg/Statistics/StExternalSector/StExchangeRates/StERForeignCurrencies/index.htm?download=xml&amp;search=&amp;lang=BG