DOM hatası! http://www.tcmb.gov.tr/kurlar/today.xml çalışmıyor.
Helper Fonksiyonum aşşağıda ki gibidir.
Çözümü Bilen duyan var mı ?
<?php
function USDtoTRY($cost){
$oneYear = 60*60*24*365;
$urls = array();
$SiteMapURL = "http://www.tcmb.gov.tr/kurlar/today.xml";
$DomDocument = new DOMDocument();
$DomDocument->preserveWhiteSpace = false;
$DomDocument->load($SiteMapURL);
$DomNodeList = $DomDocument->getElementsByTagName('Isim');
$DomNodeForexBuying = $DomDocument->getElementsByTagName('ForexBuying');
$DomNodeForexSelling = $DomDocument->getElementsByTagName('ForexSelling');
foreach($DomNodeList as $url) {
$urls[] = $url->nodeValue;
}
foreach($DomNodeForexBuying as $buying) {
$usd1[] = $buying->nodeValue;
}
foreach($DomNodeForexSelling as $selling) {
$usd2[] = $selling->nodeValue;
}
$try = $usd2[0] * $cost;
return $try;
}
?>
Hata Çıktısı ise
şöyle çalıştırdım ben, belki işine yarar :)
function USDtoTRY($cost)
{
$ch = curl_init('https://www.tcmb.gov.tr/kurlar/today.xml');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true
]);
$output = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($output);
$usd = $xml->children()[0]->ForexSelling;
return number_format($cost / $usd, 2) . '$';
}
echo USDtoTRY(100);