调用方法:
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("|<span class=bld>(.*)</span>|U", $rawdata, $matches);
$result = explode(" ", $matches[1][0]);
return round($result[0], 2);
}