【问题标题】:Google finance Currency converter not working谷歌金融货币转换器不工作
【发布时间】:2018-09-26 09:55:52
【问题描述】:

我的使用谷歌金融的货币转换器代码不起作用

$amount="10";
      $from="USD";
      $to="INR";
    $data = file_get_contents("https://finance.google.com/bctzjpnsun/converter?a=$amount&from=$from&to=$to");
    preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
    $converted = preg_replace("/[^0-9.]/", "", $converted[1]);
    echo number_format(round($converted, 3),2); exit;

我得到的结果是 0.00。

除此之外还有其他方法吗?

【问题讨论】:

    标签: php api codeigniter google-finance


    【解决方案1】:
    $amount="10";
    $from="USD";
    $to="INR";
    $url = file_get_contents('https://free.currencyconverterapi.com/api/v5/convert?q=' . $from . '_' . $to . '&compact=ultra');
    $json = json_decode($url, true);
    $rate = implode(" ",$json);
    $total = $rate * $amount;
    $rounded = round($total); 
    return $rounded;
    

    使用此代码

    【讨论】:

      【解决方案2】:

      google 的网址已经失效了

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-07
        • 2020-08-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多