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. 需要用于货币转换的API
- 4. 收集从geoplugin货币转换器返回的货币 - PHP
- 5. 货币转换API使用PHP
- 6. 货币转换器
- 7. Django货币转换
- 8. Javascript货币转换
- 9. Rails中的货币转换
- 10. 将基本脚本转换为Objective C(货币格式)
- 11. PHP将数字转换为货币
- 12. 货币转换器在HTML + PHP
- 13. 本地货币字符串转换
- 14. 谷歌应用程序脚本:转换货币,但是从转换
- 15. 基于PHP REST的Web服务提供货币转换功能
- 16. Angular2管转换货币
- 17. angularjs货币转换器
- 18. 转换条纹货币
- 19. 谷歌货币转换器
- 20. WebServicex货币转换器API
- 21. Magento完成货币转换
- 22. 货币转换器问题
- 23. 货币转换程序
- 24. 转换货币价值
- 25. 转换为货币格式
- 26. 换算货币从XML + PHP
- 27. 使用angularjs的货币转换器
- 28. 在前面转换货币的货币,angularJS
- 29. 转换成ISO 4217的数字货币代码货币名称
- 30. 印度货币的PHP货币格式?
谷歌 “的货币转换PHP脚本”。我得到了很多结果,我相信你会找到一个你喜欢的。 – ggfan 2010-04-14 05:45:28
但我需要它在codeigniter上工作 – hwd 2010-04-14 05:53:58
货币值总是相互浮动。你可以处理多少容忍/错误?您可以使用硬编码的货币地图(快捷方便),也可以挂接到Web服务以获取最新更新。 – David 2010-04-14 05:59:26