我正在使用谷歌货币转换器,它适用于所有货币但是 没有显示
的结果 ZAR - BTC
转换。
Google货币换算代码:
<?php
function convertCurrency($amount, $from, $to){
$data = file_get_contents("https://finance.google.com/finance/converter?a=$amount&from=$from&to=$to");
preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
$converted = preg_replace("/[^0-9.]/", "", $converted[1]);
return number_format(round($converted, 3),2);
}
echo convertCurrency("1000000", "ZAR", "BTC");
预期的结果应该是 8.26
来自谷歌,但它显示消息 Could not convert
我已经找到了一种方法来做到这一点..只是粘贴我的答案,为将来需要的人。
<?php
function convertCurrency($amount, $from, $to){
$data = file_get_contents("https://finance.google.com/finance/converter?a=$amount&from=$from&to=$to");
preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
$converted = preg_replace("/[^0-9.]/", "", $converted[1]);
return number_format(round($converted, 3),2);
}
convertCurrency("1", "BTC", "ZAR");
function ZARtoBTC($amount){
$BTC = convertCurrency("1", "BTC", "ZAR");
$f_amount = number_format($amount, 3);
$val = $f_amount / $BTC ;
return number_format($val, 2);
}
echo ZARtoBTC("100000");
当您从谷歌转换器收到消息时 “无法转换” - 这意味着转换
1 CURRENCY_A --> CURRENCY_B
结果太少了。在这种情况下,您需要进行反向转换 CURRENCY_A_AMOUNT / (1 CURRENCY_B --> CURRENCY_A
)
最后,我找到了解决此问题的解决方案,其中包含货币转换器的更新谷歌URL。
点击这里 阅读完整的解决方案,谢谢我