Created
June 28, 2018 11:04
-
-
Save BAHC/33c4f8ebc8993d258b7fccb43cfcdf06 to your computer and use it in GitHub Desktop.
Turkish Lira Official Exchange Rate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Turkish Lira Official Exchange Rate | |
**/ | |
function turkey_exchange_rate($_opt='', $_signs = 2) | |
{ | |
$res = null; | |
$url = 'http://www.tcmb.gov.tr/kurlar/today.xml'; | |
$xml = @simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA); | |
$_errors = libxml_get_errors(); | |
if(!count($_errors)) | |
{ | |
$_count = count($xml->Currency); | |
$_currency = []; | |
for($i=0;$i<$_count;$i++) | |
{ | |
$_code = (string) $xml->Currency[$i]->attributes()->CurrencyCode; | |
$_price = (string) $xml->Currency[$i]->BanknoteBuying; | |
$_currency[ $_code ] = $_price; | |
} | |
if(isset($_currency[$_opt])) | |
{ | |
$res = number_format($_currency[$_opt], (int)$_signs, '.', ''); | |
} | |
} | |
return $res; | |
} | |
echo turkey_exchange_rate('USD', 3); | |
echo turkey_exchange_rate('EUR'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment