v2.5.2
Giriş yap

DOM hatası! http://www.tcmb.gov.tr/kurlar/today.xml çalışmıyor.

4rival
1,251 defa görüntülendi

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

frdgk
1290 gün önce

Senin fonksiyonunla alakası yok ama tcmb bildiğim kadarıyla bir gün öncesinin kurlarını gösteriyor. Aşağıda ki örnekte anlık olarak alabilirsin, böylesinin senin için daha verimli olacağını düşündüm.


function USDtoTRY($cost){
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'https://kur.doviz.com/api/v5/converterItems');
  curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER ['HTTP_USER_AGENT']);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $result = curl_exec($ch);
  $json = json_decode($result, true);

  foreach($json[0] as $row){
    if($row['code'] == 'USD'){
      return $row['buying'] * $cost;
    }
  }
}

$TL = USDtoTRY(10);