adidaxx Posted March 17, 2009 Share Posted March 17, 2009 Hi, I have two currencies now: euro(default), and ron - in admin euro value:1.000000 and ron value:4.2806 (from oanda) - and i have to update every day the rate currencies -so i get a php file, witch connect to national bank and get the currencies rate( 1euro=xxron) automatic; the script is: <?php ////////////////////////////////////////////// // FUNCTIONEAZA CU PHP5, CURL si SimpleXML. // Fisierul xml BNR http://www.bnro.ro/nbrfxrates.xml // http://www.skullbox.info/ ////////////////////////////////////////////// // Trebuie sa iau XML-ul de pe bnr.ro si sa-l salvez in $curs; $url = 'http://www.bnro.ro/nbrfxrates.xml'; // Daca exista CURL, folosim CURL. Daca nu, folosim file_get_contents(); if( function_exists('curl_init') ) { $curl_handle=curl_init(); curl_setopt($curl_handle,CURLOPT_URL,$url); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2); curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); $curs = curl_exec($curl_handle); curl_close($curl_handle); } else { $curs = file_get_contents($url); } // OK, avem fisierul nbrfxrates.xml. Acum trebuie sa il citim // pentru asta avem nevoie de SimpleXML if( !class_exists('SimpleXMLElement') ){ // Daca nu suporta SimpleXML e naspa // Nu extind ca nu am chef sa ma complic inutil // Oricine vrea sa ma completeze e binevenit :-) echo 'Serverul nu suporta SimpleXML'; exit; } // Daca am ajuns pana aici toate-s bune si ne putem pune pe treaba :-) $rates = array(); $xml = new SimpleXMLElement($curs); foreach( $xml->Body->Cube->Rate as $rate ){ $final = array(); foreach( $rate->attributes() as $att => $value ){ if( strcmp($att,'currency') == 0 ) $final['currency'] = (string) $value; if( strcmp($att,'multiplier') == 0 ) $final['multiplier'] = (string) $value; } $final['rate'] = (string) $rate; if( empty($final['multiplier']) ) $final['multiplier'] = 1; array_push($rates,$final); } // Daca am ajuns aici, datele sunt pastrate in $rates //print_r($rates); // EXEMPLU EUR 7, USD 18, pentru toate valorile folositi print_r($rates); echo $rates[7]['currency'].' - '.$rates[7]['rate']; ?> now what I want is to use this php file, but i don't know how to use this, what to change; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.