PHP code example of mlevent / tcmb

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

    

mlevent / tcmb example snippets


use Mlevent\Tcmb\Tcmb;

$tcmb = new Tcmb;

// Dolar kuruna ait detaylar
var_dump($tcmb->get('USD'));

// Bu kullanım da aynı sonucu verecektir
var_dump($tcmb->getUsd());

Mlevent\Tcmb\Currency Object
(
    [currencyCode]    => USD
    [currencyName]    => US DOLLAR
    [currencyAlias]   => ABD DOLARI
    [forexBuying]     => 27.0254
    [forexSelling]    => 27.0741
    [banknoteBuying]  => 27.0065
    [banknoteSelling] => 27.1147
    [crossRateUSD]    =>
    [crossRateOther]  =>
)

echo $tcmb->getUsd()->forexSelling; // 27.0741

$tcmb = (new Tcmb)->setDate('16/05/2022');

echo $tcmb->convert('USD', 'TRY'); // 27.0741

echo $tcmb->convertUsdTry(10); // 270.741

use Mlevent\FileCache\FileCache;
use Mlevent\Tcmb\Tcmb;

$tcmb = new Tcmb;

// Veriler 60 saniye boyunca diskte saklanacak
$data = (new FileCache)->refresh('exchange-rates', function () use ($tcmb) {
    return $tcmb->fetchExchangeRates();
}, 60);

// Veri içe aktarılıyor
$tcmb->setExchangeRates($data);

echo $tcmb->getUsd()->forexSelling; // 27.0741

/**
 * Döviz Listesi
 * @return array
 */
$tcmb->getCurrencies();

/**
 * Tüm Döviz Cinslerine Ait Kur Bilgileri
 * @return array
 */
$tcmb->getExchangeRates();

/**
 * TCMB Bülten Yayınlanma Tarihi
 * @return string
 */
$tcmb->getBulletinDate();

/**
 * TCMB Bülten Numarası
 * @return string
 */
$tcmb->getBulletinNumber();