谷歌财经货币转换器不起作用



我的使用谷歌财经的当前转换器代码不起作用

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

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

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

使用此代码

谷歌的网址不再有效

最新更新