<?phpclass TCMBDovizKurlari{//USDTRY EURTRYvar $kurlar;public function __construct(){if(!$tcmb= @file("http://www.tcmb.gov.tr/kurlar/".date("Ym")."/".date("dmY").".xml")){$sonCuma = new DateTime("last friday"); // Hata sonu tatiliyse son cumayı alır.$tcmb= file("http://www.tcmb.gov.tr/kurlar/".$sonCuma->format("Ym")."/".$sonCuma->format("dmY").".xml");}$this->kurlar[]=$tcmb[7];$this->kurlar[]=$tcmb[8];$this->kurlar[]=$tcmb[43];$this->kurlar[]=$tcmb[44];}public function usd_alis(){return $this->kurlar[0];}public function usd_satis(){return $this->kurlar[1];}public function eur_alis(){return $this->kurlar[2];}public function eur_satis(){return $this->kurlar[3];}}$a=new TCMBDovizKurlari;echo $a->usd_alis()."<br>";echo $a->usd_satis()."<br>";echo $a->eur_alis()."<br>";echo $a->eur_satis()."<br>";
Çıktısı
4.44024.44825.24125.2507