3
A
回答
2
從http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html#dev
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 € = '.$rate[1].' '.$currencyCode[1].'<br />';
//--------------------------------------------------
// Here you can add your code for inserting
// $rate[1] and $currencyCode[1] into your database
//--------------------------------------------------
}
}
}
?>
腳本不是最好的拍攝,但話又說回來,你剛纔問了給我,朱德codez。
1
可以計算匯率很簡單,如:
$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];
0
我上週寫了一個笨貨幣轉換模型。你可以從here下載。
它使用歐洲中央銀行的XML feed,每週更新一次。
2
您可以使用以下代碼輕鬆地將貨幣轉換爲Google轉換。瞭解更多關於貨幣轉換庫在PHP與谷歌在這裏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;
}
0
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class CurrencyCon extends CI_Controller {
public function index()
{
$dollarValue=$this->convert_currency('USD', 'INR',1890);//parameter3 give the amount to be converted.
echo 'Actual Rate '.$dollarValue."";
echo 'Round Figure '.$con_dollor = round($dollarValue,2);
}
function convert_currency($currency_from,$currency_to,$currency_input)
{
$yql_base_url = "http://query.yahooapis.com/v1/public/yql";
$yql_query = 'select * from yahoo.finance.xchange where pair in ("'.$currency_from.$currency_to.'")';
$yql_query_url = $yql_base_url . "?q=" . urlencode($yql_query);
$yql_query_url .= "&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
$yql_session = file_get_contents($yql_query_url);
$yql_json = json_decode($yql_session,true);
$currency_output = (float) $currency_input*$yql_json['query']['results']['rate']['Rate'];
return $currency_output;
}
}
? >
0
我這裏期運用Google財經API。使用這一個:
function currencyConverter($from_Currency, $to_Currency, $amount) {
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);
$get = file_get_contents("https://finance.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency");
$get = explode("", $get);
$get = explode("", $get[1]);
$converted_currency = preg_replace("/[^0-9\.]/", null, $get[0]);
return $converted_currency;
}
Core php ======== $converted_currency=currencyConverter('USD', 'INR', 1); echo $converted_currency; Codeigniter =========== $converted_currency=$this->currencyConverter('USD', 'INR', 1); echo $converted_currency;
相關問題
- 1. 如何貨幣Java腳本轉換
- 2. 轉換貨幣
- 3. 使用PHP的貨幣轉換器
- 4. 用於轉換爲貨幣的NSNumberFormatter
- 5. 需要用於貨幣轉換的API
- 6. 貨幣兌換腳本不起作用
- 7. 收集從geoplugin貨幣轉換器返回的貨幣 - PHP
- 8. 貨幣轉換API使用PHP
- 9. Javascript貨幣轉換
- 10. 貨幣轉換 - AngularJS
- 11. Django貨幣轉換
- 12. 貨幣轉換器
- 13. Rails中的貨幣轉換
- 14. 將基本腳本轉換爲Objective C(貨幣格式)
- 15. PHP將數字轉換爲貨幣
- 16. 貨幣轉換器在HTML + PHP
- 17. 本地貨幣字符串轉換
- 18. 谷歌應用程序腳本:轉換貨幣,但是從轉換
- 19. 基於PHP REST的Web服務提供貨幣轉換功能
- 20. greasemonkey貨幣轉換器
- 21. 谷歌貨幣轉換器
- 22. Angular2管轉換貨幣
- 23. 轉換爲貨幣格式
- 24. Bash程序轉換貨幣
- 25. angularjs貨幣轉換器
- 26. 轉換爲貨幣格式
- 27. 貨幣轉換程序
- 28. 安卓貨幣轉換
- 29. 貨幣對數轉換軌
- 30. 轉換條紋貨幣
谷歌 「的貨幣轉換PHP腳本」。我得到了很多結果,我相信你會找到一個你喜歡的。 – ggfan 2010-04-14 05:45:28
但我需要它在codeigniter上工作 – hwd 2010-04-14 05:53:58
貨幣值總是相互浮動。你可以處理多少容忍/錯誤?您可以使用硬編碼的貨幣地圖(快捷方便),也可以掛接到Web服務以獲取最新更新。 – David 2010-04-14 05:59:26