Para birimi dönüştürme için php script

4 Cevap php

Ben para birimi dönüştürme yapan bir php script arıyorum.

Nerede CodeIgniter ile çalışır birini bulabilirim?

4 Cevap

http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html#dev alınan

How to parse the data
This is just an example

<?php
//This is a PHP (4/5) script example on how eurofxref-daily.xml can be parsed 

//Read eurofxref-daily.xml file in memory 
$XMLContent= file("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
//the file is updated daily between 2.15 p.m. and 3.00 p.m. CET

foreach ($XMLContent as $line) {
        if (ereg("currency='([[:alpha:]]+)'",$line,$currencyCode)) {
            if (ereg("rate='([[:graph:]]+)'",$line,$rate)) {
                    //Output the value of 1 EUR for a currency code 
                    echo '1 &euro; = '.$rate[1].' '.$currencyCode[1].'<br />';
                    //--------------------------------------------------
                    // Here you can add your code for inserting
                    // $rate[1] and $currencyCode[1] into your database
                    //--------------------------------------------------
            }
        }
}
?> 

Dizelerin iyi, ama sonra tekrar, sadece ver-teh-codez için istedi.

Sen aşağıdaki kod ile kolayca google dönüşüm ile döviz dönüştürebilirsiniz. Google PHP ile Döviz Dönüşüm kütüphane hakkında daha fazla okuyun burada http://mydons.com/currency-conversion-library-in-codeigniter/

public function getResult(){           
$result = file_get_contents($this->googleUrl);/* Convert the above result into Array */                           
$result = explode('"', $result);/* Right side text*/           
$convertedAmount = explode(' ', $result[3]);           
$conversion = $convertedAmount[0];           
$conversion = $conversion * $this->amount;          
$conversion = round($conversion, 2);//Get text for converted currency               
$rightText = ucwords(str_replace($convertedAmount[0],"",$result[3]));//Make right hand side string           

$rightText = $conversion.$rightText;/* Left side text*/           
$googleLeft = explode(' ', $result[1]);           
$fromAmount = $googleLeft[0];//Get text for converted from currency              

$fromText = ucwords(str_replace($fromAmount,"",$result[1])); //Make left hand side string           
$leftText = $this->amount." ".$fromText;             
return $leftText." = ".$rightText; 
}

Eğer döviz kurları oldukça basit gibi hesaplayabilirsiniz:

$from = "GBP";
$to = "USD";
$url = 'http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency='.$from.'&ToCurrency='.$to;
$rate = simplexml_load_file($url);
echo 'Rate from '.$from.' to '.$to.' is: '.$rate[0];

Geçen hafta CodeIgniter para birimi dönüştürme modelini yazdı. Sen here adlı eğer indirebilirsiniz.

Bu hafta içi her gün güncellenen Avrupa Merkez Bankası'nın XML beslemesini kullanır.