Jump to content

Recommended Posts

Posted

Aveti mai jos un script, care preia cursul valutar de la BNR. Asta inseamna ca daca euro creste sau scare, atunci se va updata automat.

Aveti un exemplu al codului de mai jos, in actiune aici: :link:

<?
   /*
    * Class cursBnrXML v1.0
    * Author: Ciuca Valeriu
    * E-mail: vali.ciuca@gmail.com
    * This class parses BNR's XML and returns the current exchange rate
    *
    * Requirements: PHP5
    *
    * Last update: June 2008, 03    
    * More info: www.curs-valutar-bnr.ro
    *
    */
   
    class cursBnrXML
    {
        /**
        * xml document
        * @var string
        */
        var $xmlDocument = "";
       
       
        /**
        * exchange date
        * BNR date format is Y-m-d
        * @var string
        */
        var $date = "";
       
       
        /**
        * currency
        * @var associative array
        */
        var $currency = array();
       
       
        /**
        * cursBnrXML class constructor
        *
        * @access        public
        * @param         $url        string
        * @return        void
        */
       function cursBnrXML($url)
       {
           $this->xmlDocument = file_get_contents($url);
           $this->parseXMLDocument();
       }
       
       /**
        * parseXMLDocument method
        *
        * @access        public
        * @return         void
        */
       function parseXMLDocument()
       {
            $xml = new SimpleXMLElement($this->xmlDocument);
           
            $this->date=$xml->Header->SendingDate;
           
            foreach($xml->Body->Cube->Rate as $line)    
            {                      
                $this->currency[]=array("name"=>$line["currency"], "value"=>$line, "multiplier"=>$line["multiplier"]);
            }
       }
       
       /**
        * getCurs method
        *
        * get current exchange rate: example getCurs("USD")
        *
        * @access        public
        * @return         string/boolean in case of failure
        */
       function getCurs($currency)
       {
           foreach($this->currency as $line)
           {
               if($line["name"]==$currency)
               {
                   return $line["value"];
               }
           }
           
           return false;
       }
    }
   
    //--------------------------------------------------------------------------------------------------
    //@an example of using the cursBnrXML class
   
    $curs=new cursBnrXML("http://www.bnro.ro/nbrfxrates.xml");
   
    print $curs->date;
   
    print "<hr>";
    print "USD: ".$curs->getCurs("USD");
    print "<hr>";
    print "EUR: ".$curs->getCurs("EUR");
    print "<hr>";
?> [/code]

  • Downvote 1

Te-ai inregistrat? Ne-ar placea sa te prezinti.

Cum pot sustine forumul?
Cumpara de la eMag folosind acest link.
--------------------
oG2BN9d.gifse1WdXd.gifQG6MtmI.gifRHYjDzD.gifG5p1wui.gif

  • 11 months later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.