php 和 java 美刀,通过GOOGLE(谷歌) API获取实时货币汇率(人民币和美金)的PHP代码
調用方法:
echo $this->currency("USD", "CNY", 1);die;
當前(2016年6月11日匯率是6.56)
函數:
function currency($from_Currency, $to_Currency, $amount) {
$url = "https://www.google.com/finance/converter?a=" . $amount . "&from=" . $from_Currency . "&to=" . $to_Currency;
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$rawdata = curl_exec($ch);
curl_close($ch);
$matches = array();
preg_match_all("|(.*)|U", $rawdata, $matches);
$result = explode(" ", $matches[1][0]);
return round($result[0], 2);
}
總結
以上是生活随笔為你收集整理的php 和 java 美刀,通过GOOGLE(谷歌) API获取实时货币汇率(人民币和美金)的PHP代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 数字转换为货币,php中数字转换
- 下一篇: SAP中检查货币代码