• 16-10-2010, 17:43:46
    #1
    Eposta Aktivasyonu Gerekmekte
    İstiyen vardı, bir ara lazım olmuştu banada yazmıştım.
    function TCMB()
    {
            try
            {
                $data         = file_get_contents("http://www.tcmb.gov.tr/kurlar/today.xml");
                $xmlData     = new SimpleXMLElement($data);
                $name         = $xmlData->xpath("/Tarih_Date/Currency//@Kod");
                $buying       = $xmlData->xpath("/Tarih_Date/Currency/ForexBuying");
                $selling        = $xmlData->xpath("/Tarih_Date/Currency/ForexSelling");
                $color = "";
                $str = '<table border="0"  style="font-size: 12px; font-family: tahoma;"><tr style="font-weight: bold; text-align: center; background-color: #dbdbdb;"><td width="20%" style="padding: 3px;">Döviz</td><td width="25%">Alış</td><td width="25%">Satış</td></tr>';
                $z = 1;
                $k = 0;
                $size = sizeof($buying);
                for($i=0; $i<$size; $i++):
                
                    if(($z % 2) == 0) {$color = 'eff0f1'; if($k == 0) {$z++; $k++;}} else $renk = "ffffff";
                    if($i != 2) $str .='<tr style="background-color: #' . $color . ';"><td style="padding: 4px; font-weight: bold;">' . $name[$i] . '</td><td>' . $buying[$i] . '</td><td>' . $selling[$i] . '</td></tr>';
                    $z++;
    
                endfor; 
                $str .= '</table><br />';
                
                echo $str;
            }
            catch(Exception $ex)
            {
                echo '<script type="text/javascript">alert("OOpps ! Kur değerleri şuan alınamıyor.\n\n' . $ex->getMessage() . '")</script>';
            }
    }
  • 16-10-2010, 19:41:26
    #2
    Ben de sınıflı yazmıştım. Paylaşayım:

    doviz_sinif.php
    <?php
    
        class Doviz {
    
            function Getir() {
    
                $adres = "http://www.tcmb.gov.tr/kurlar/today.xml";
    
                $ba1= '<Currency Kod="'.$this->Tipi.'" CurrencyCode="'.$this->Tipi.'">';
                $bi1 = '</Currency>';
    
                $ba2 = '<ForexSelling>';
                $bi2 = '</ForexSelling>';
    
                $cek1 = @file_get_contents($adres);
    
                $p11 = explode($ba1,$cek1);
                $p12 = explode($bi1,$p11[1]);
    
                $p21 = explode($ba2,$p12[0]);
                $p22 = explode($bi2,$p21[1]);
    
                $dolar = $p22[0];
    
                echo "<b>".$this->Tipi.":</b> ".$dolar." TL.<br>";
    
            }
    
        }
    
    ?>
    Kullanımı:

    doviz.php
    <?php
    
        require "doviz_sinif.php";
    
        $Doviz = new Doviz();
    
        $Doviz->Tipi = "USD";
        $Doviz->Getir();
    
        $Doviz->Tipi = "EUR";
        $Doviz->Getir();
    
    ?>
    Çıktısı