Google Finance货币转换器无法正常工作

时间:2018-09-26 09:55:52

标签: php api codeigniter google-finance

我的使用Google财务的货币转换器的代码不起作用

$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。

除了此以外,还有其他替代方法吗?

2 个答案:

答案 0 :(得分:3)

$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;

使用此代码

答案 1 :(得分:1)

google的网址不再起作用

相关问题