0
Q
轉換貨幣
A
回答
0
我使用谷歌金融計算器爲用戶與應用互動,你可以在PHP中使用它獲取轉換的數據。
function convertCurrency($amount, $from, $to){
$url = "https://www.google.com/finance/converter?a=$amount&from=$from&to=$to";
$data = file_get_contents($url);
preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
$converted = preg_replace("/[^0-9.]/", "", $converted[1]);
return round($converted, 3);
}
我使用的是USD到INR的轉換器。 調用這個函數
echo convertCurrency(1, "USD", "INR");
0
你不能做到這一點的Java代碼原因匯率flatuating每次..你可以當匯率改變使用這個API會自動更新---
<?php
$from = $_POST["from"];
$to = $_POST["to"];
$amount = $_POST["amount"];
$rawData = currencyConvert($from,$to,$amount);
$regex = '#\<span class=bld\>(.+?)\<\/span\>#s';
preg_match($regex, $rawData, $converted);
$result = $converted[0];
preg_match('!\d+(?:\.\d+)?!', $result, $result);
echo $result[0];
function currencyConvert($from,$to,$amount){
$url = "http://www.google.com/finance/converter?a=$amount&from=$from&to=$to";
$request = curl_init();
$timeOut = 0;
curl_setopt ($request, CURLOPT_URL, $url);
curl_setopt ($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($request, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($request, CURLOPT_CONNECTTIMEOUT, $timeOut);
$response = curl_exec($request);
curl_close($request);
return $response;
}
?>
相關問題
- 1. Javascript貨幣轉換
- 2. 貨幣轉換 - AngularJS
- 3. Django貨幣轉換
- 4. 貨幣轉換器
- 5. greasemonkey貨幣轉換器
- 6. 谷歌貨幣轉換器
- 7. Angular2管轉換貨幣
- 8. 轉換爲貨幣格式
- 9. Bash程序轉換貨幣
- 10. angularjs貨幣轉換器
- 11. 轉換爲貨幣格式
- 12. 貨幣轉換程序
- 13. 安卓貨幣轉換
- 14. 貨幣對數轉換軌
- 15. 轉換條紋貨幣
- 16. Magento完成貨幣轉換
- 17. 做一個貨幣轉換
- 18. 貨幣轉換器問題
- 19. 貨幣轉換器JSONp
- 20. Rails中的貨幣轉換
- 21. C++轉換爲貨幣值
- 22. WebServicex貨幣轉換器API
- 23. 轉換貨幣價值
- 24. 貨幣轉換器不轉換
- 25. 在前面轉換貨幣的貨幣,angularJS
- 26. 轉換成ISO 4217的數字貨幣代碼貨幣名稱
- 27. 將貨幣/貨幣轉換爲Cent,反之亦然
- 28. 在DB2中轉換爲貨幣或貨幣格式
- 29. 收集從geoplugin貨幣轉換器返回的貨幣 - PHP
- 30. 計算後將雙貨幣轉換爲貨幣
你意識到匯率波動,對吧? Java沒有內置任何東西來處理這個問題。 –
您可以使用谷歌API:[鏈接](https://www.google.com/finance/converter?a=1&from=USD&to=INR)或歐洲央行API:[鏈接](http://www.ecb .europa.eu/stats/eurofxref/eurofxref-daily.xml)更新貨幣值 –