【发布时间】:2018-06-19 06:36:10
【问题描述】:
我在 php 中通过使用 file_get_content 使用谷歌货币转换 API,但由于出现错误无法获取输出,所以如何在 PHP 中使用以下 API 转换任何货币。
<?php
function convertCurrency($amount, $from, $to)
{
$url = "http://www.google.com/finance/converter?a=$amount&from=$from&to=$to";
$data = file_get_contents($url);
preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
return $converted[1];
}
echo convertCurrency(1500, 'USD', 'INR');
?>
出现这样的错误
Message: file_get_contents(http://www.google.com/finance/converter?a=1500&from=USD&to=INR): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
【问题讨论】:
-
上面已经写了
403 Forbidden,所以不行,你不能这样刮 -
@Ghost 那么如何做到这一点,请给我建议如何在 php 中解决这种货币转换
-
你可以在这里查看这些答案,stackoverflow.com/questions/3139879/…
-
尝试检查哪些符合您的要求