利用yahoo汇率接口实现实时汇率转换示例 汇率转换器
更新时间:2014年01月14日 16:52:00 作者:
这篇文章主要介绍了利用yahoo汇率接口实现实时汇率转换示例,大家参考使用吧
代码如下:
复制代码 代码如下:
function getExchangeRate($from_Currency,$to_Currency)
{
$amount = urlencode($amount);
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);
$url = "download.finance.yahoo.com/d/quotes.html?s=".$from_Currency.$to_Currency."=X&f=sl1d1t1ba&e=.html";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$rawdata = curl_exec($ch);
curl_close($ch);
$data = explode(',', $rawdata);
return $data[1];
}
//调用方法
echo getExchangeRate("CNY","USD");
相关文章
Thinkphp 框架配置操作之动态配置、扩展配置及批量配置实例分析
这篇文章主要介绍了Thinkphp 框架配置操作之动态配置、扩展配置及批量配置,结合实例形式分析了Thinkphp配置操作中动态配置、扩展配置及批量配置基本原理、实现方法与相关注意事项,需要的朋友可以参考下2020-05-05
laravel框架中间件 except 和 only 的用法示例
这篇文章主要介绍了laravel框架中间件 except 和 only 的用法,简单说明了中间件 except 和 only的功能,并结合实例形式分析了laravel框架中间件 except 和 only 相关使用技巧,需要的朋友可以参考下2019-07-07
yii2整合百度编辑器umeditor及umeditor图片上传问题的解决办法
这篇文章主要介绍了yii2整合百度编辑器umeditor及umeditor图片上传问题的解决办法的相关资料,需要的朋友可以参考下2016-04-04


最新评论