Doğru Cevap
-
hocam new ile class 'ı çağır ve bi deişkene ata.
$c = new currency; echo $c->money['EUR']."<br>"; echo $c->money['USD'];
umarım demek istediğin buydu =)
Cevaplar
Hiç cevap bulunamadı.
<?php // TCMB Class -> kirpit et gmail dat com class Currency { var $xml = 'http://www.tcmb.gov.tr/kurlar/today.xml'; var $cache = 'cache/currency.dat'; // cache file : 777 var $expire = 60; // last modification in minutes // currency var $money = array( 'EUR' => array('SYM' => '€'), 'USD' => array('SYM' => '$'), 'GBP' => array('SYM' => '£'), 'NOK' => array('SYM' => 'kr'), 'SEK' => array('SYM' => 'kr'), 'JPY' => array('SYM' => '¥'), 'TRL' => array( 'SYM' => 'TL', 'UNIT' => 1, 'ISIM' => 'TÜRK LİRASI', 'CURRENCYNAME' => 'TURKISH LIRA', 'FOREXBUYING' => 1, 'FOREXSELLING' => 1, 'BANKNOTEBUYING' => 1, 'BANKNOTESELLING' => 1 ) ); // default exec func function Currency() { // chech cache file exist or expired $mod = (time()-@filemtime($this->cache))/60; // modified x min before if( !file_exists($this->cache) || ($mod > $this->expire) ) { $this->CreateCache(); } // load from file $fd = fopen($this->cache, "r"); $moneys = fread($fd, filesize($this->cache) ); fclose($fd); $this->money = unserialize($moneys); // set default curr code and value if($_GET['curr']) $_SESSION['DEF_CURR'] = $_GET['curr']; if(array_key_exists($_SESSION['DEF_CURR'], $this->money)) { $this->DefCurr = $this->money[$_SESSION['DEF_CURR']]; } else { $this->DefCurr = $this->money['EUR']; // Default Currency } } // create cache file function CreateCache() { // leave file if some reading error if( !($this->content = @file_get_contents($this->xml)) ) { return false; } $xml_parser = xml_parser_create(); xml_set_object($xml_parser, $this); xml_set_element_handler($xml_parser, 'StartParse', 'StopParse'); xml_set_default_handler($xml_parser, 'Data'); xml_parse($xml_parser, $this->content); // unset values xml_parser_free($xml_parser); unset($this->content); unset($this->parsing); unset($this->tmp_attr); // write into cache file $fd = @fopen($this->cache, 'w'); @fwrite($fd, serialize($this->money) ); @fclose($fd); } // [Currency] parsing sub func function StartParse($parser, $elName, $elAttrs) { // new currency dom starting if(($elName == 'CURRENCY') && array_key_exists($elAttrs['CURRENCYCODE'], $this->money)) { $this->parsing = $elAttrs['CURRENCYCODE']; } // set currency value temp if($this->parsing) { $this->tmp_attr = $elName; } } // [Currency] parsing sub func function StopParse($parser, $elName) { if($elName == 'CURRENCY') { $this->parsing = NULL; } } // [Currency] parsing sub func function Data($parser, $data) { if($this->parsing && $this->tmp_attr) { $this->money[$this->parsing][$this->tmp_attr] = utf8_encode($data); } } } ?>