0

我正在使用 Google Currency Converter API,但由于某些原因,我不知道它向我显示所有值 0。它有时有效,但大多数情况下它显示 0 作为值,无法确定 Google 的 API 是否已关闭或我的代码中有问题.

$final_rateUSD = // Current USD value + our commission
$rateWithcommsellvalue = // Current USD value + our commission
$final_rateAUD = get_currency('USD', 'AUD', $final_rateUSD);
$final_rateSellAUD = get_currency('USD', 'AUD', $rateWithcommsellvalue);

function get_currency($from_Currency, $to_Currency, $rate) {
    $amount = urlencode($rate);
    $from_Currency = urlencode($from_Currency);
    $to_Currency = urlencode($to_Currency);
    $get = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency");
    $get = explode("<span class=bld>", $get);
    $get = explode("</span>", $get[1]);
    $converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]);
    return round($converted_amount, 5); 
}
4

0 回答 0