问题 Google Finance货币转换器


我正在使用谷歌货币转换器,它适用于所有货币但是 没有显示  的结果 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


12209
2018-02-24 06:52


起源

谷歌链接说几种不同的货币相同的东西比特币。编程问题怎么样?你没有尝试使用网络浏览器链接吗? - James Z
我投票将此问题视为非主题,因为SO无法告诉您为什么您会获得某个网页的结果 - James Z
先检查我的答案。 - Coffee
这不是因为网页浏览器#James .. - Coffee
我不能先检查你之后发布的东西,但是,这根本与编程无关。 - James Z


答案:


我已经找到了一种方法来做到这一点..只是粘贴我的答案,为将来需要的人。

<?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");

6
2018-02-24 08:01



做得好 !!!! - syed


当您从谷歌转换器收到消息时 “无法转换”  - 这意味着转换
1 CURRENCY_A --> CURRENCY_B 结果太少了。在这种情况下,您需要进行反向转换 CURRENCY_A_AMOUNT / (1 CURRENCY_B --> CURRENCY_A


5
2018-03-06 09:39



谢谢你让我们知道(y) - Coffee


最后,我找到了解决此问题的解决方案,其中包含货币转换器的更新谷歌URL。

点击这里 阅读完整的解决方案,谢谢我


0
2018-03-22 08:00



不工作..检查: ibb.co/g4aAPc - Coffee