TCMB Kurlar

Class

<?php
/*
	Class: TCMBKur
	Author: ibasoglu
	Website: http://www.ibasoglu.com
	Date: 27.01.2015
*/

class TCMBKur{
	private $URL = 'http://www.tcmb.gov.tr/kurlar/today.xml';
	private $kur = array();
	public $tarih = '';
	public $bulten_no = '';

	public function TCMBKur(){
		$xml = simplexml_load_file($this->URL);
		
		$this->tarih = (string) $xml->attributes()->Tarih;
		$this->bulten_no = (string) $xml->attributes()->Bulten_No;

		foreach ($xml->Currency as $d) {
			$this->kur[(string)$d->attributes()->Kod] = array(
				'Isim' 	=> (string) $d->Isim,
				'DA'	=> (float) $d->ForexBuying,
				'DS'	=> (float) $d->ForexSelling,
				'EA'	=> (float) $d->BanknoteBuying,
				'ES'	=> (float) $d->BanknoteSelling
			);
		}
	}

	public function Convert($de = array()){
		$results = array();

		foreach ($de as $d) {

				$kur = $this->kur[$d[0]];

				$results[] = array(
					'dkod' 	=> $d[0] . '/TRY',
					'birim'	=> $d[1],
					'dcins'	=> $kur['Isim'],
					'DA' 	=> $kur['DA'] * $d[1],
					'DS'	=> $kur['DS'] * $d[1],
					'EA' 	=> $kur['EA'] * $d[1],
					'ES' 	=> $kur['ES'] * $d[1]
				);
		}

		return $results;
	}
}

 

Kullanımı

<html>
	<head>
		<meta charset="utf-8">
	</head>
	<body>
		<table border="1" style="border:1px">
			<thead>
				<tr>
					<th>Döviz Kod</th>
					<th>Birim</th>
					<th>Döviz Cinsi</th>
					<th>Döviz Alış</th>
					<th>Döviz Satış</th>
					<th>Efektif Alış</th>
					<th>Efektif Satış</th>
				</tr>
			</thead>
			<tbody>

<?php
require 'TCMBKur.class.php';

$TCMB = new TCMBKur();

$d = array(
	array('USD', 1.00),
	array('AUD', 1.00),
	array('DKK', 1.00),
	array('USD', 1.00),
	array('EUR', 1.00),
	array('GBP', 1.00),
	array('CHF', 1.00),
	array('SEK', 1.00),
	array('CAD', 1.00),
	array('KWD', 1.00),
	array('NOK', 1.00),
	array('SAR', 1.00),
	array('JPY', 1.00),
	array('BGN', 1.00),
	array('RON', 1.00),
	array('RUB', 1.00),
	array('IRR', 1.00),
	array('CNY', 1.00),
	array('PKR', 1.00)
);

$r = $TCMB->Convert($d);

foreach ($r as $de) {
	echo "<tr>
			<td>{$de['dkod']}</td>
			<td>{$de['birim']}</td>
			<td>{$de['dcins']}</td>
			<td>{$de['DA']}</td>
			<td>{$de['DS']}</td>
			<td>{$de['EA']}</td>
			<td>{$de['ES']}</td>
		</tr>";
}

echo "</tbod>
	<tfoot>
		<tr>
			<td colspan=\"7\">Tarih: {$TCMB->tarih}  Bülten No: {$TCMB->bulten_no}</td>
		</tr>
	</tfoot>"
?>

		</table>
	</body>
</html>

SnapCrab_No-0005