首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用谷歌金融货币转换代码点火器。工作了2-4个月,但现在突然之间转换被禁用?

使用谷歌金融货币转换代码点火器。工作了2-4个月,但现在突然之间转换被禁用?
EN

Stack Overflow用户
提问于 2018-03-19 05:18:31
回答 2查看 4.5K关注 0票数 0

使用谷歌金融和雅虎金融货币转换为代码点火器。工作了2-4个月,但现在突然之间转换变得禁用??

我的代码片段(帮助文件代码):

代码语言:javascript
复制
<?php

if (!function_exists('convertCurrency')) {

    function convertCurrency($amount,$from_Currency,$to_Currency) {
        $amount = urlencode($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("<span class=bld>",$get);
        $get = explode("</span>",$get[1]);
        $converted_currency = preg_replace("/[^0-9\.]/", null, $get[0]);
        return number_format($converted_currency,2,'.','');
    }
}

在控制器和视图文件中调用该函数,如下所示:

代码语言:javascript
复制
<?php echo convertCurrency($amount, "INR", "USD");?>

工作了2-4个月,但现在它在??之间失去了功能。

我也尝试过卷曲,但没有得到链接.的响应。

请建议我正确的想法??

EN

回答 2

Stack Overflow用户

发布于 2018-03-20 10:03:04

下面的代码可以工作。试试看:)

代码语言:javascript
复制
$url = "http://www.xe.com/currencyconverter/convert/?
     Amount=1&From=USD&To=INR";

$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('uccResultAmount', $rawdata);
@$data = explode('uccToCurrencyCode', $data[1]);

$amount = preg_replace('/[^0-9,.]/', '', $data[0]);
票数 0
EN

Stack Overflow用户

发布于 2018-04-19 06:47:59

您还可以使用:

代码语言:javascript
复制
$res = file_get_contents("https://finance.google.com/bctzjpnsun/converter?a=1&from=USD&to=CAD");

这是谷歌计算器,并将工作。

现在您必须解析这个响应:

代码语言:javascript
复制
$res = explode("<span class=bld>",$res);
$res = explode("</span>",$res[1]);
$rate= preg_replace("/[^0-9\.]/", null, $get[0]);
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49356238

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档