2013-07-21 35 views

回答

19

我在这里所描述的相同的问题可用:https://stackoverflow.com/a/19786423/2819754

我用@hobailey答案一个临时的解决办法,直到我可以把它升级到另一个版本或谷歌决定做一个适当的API。

随着谷歌改变了网址

https://www.google.com/finance/converter?a 

所以我找到了解决方法是如下。

$amount = urlencode($amount); 
    $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]); 

感谢@hobailey这个小修补程序。

+1

https://www.google.com/finance/convertera=$amount&from=$from_Currency&to=$to_Currency - 我认为需要有一个“?”之后“转换器”为此工作。 –

+0

@AaronFisher那个链接已经死了。 – adamj

+0

@adamj这应该工作:https://www.google.com/finance/converter?a=10&from=USD&to=GBP('a'是金额) –

3

iGoogle已过期,但尚未过帐您发布的小工具链接。目前它返回 200 OK可能是你想要的信息。

更新: 它也过期了。 目前没有小工具可用。

更新:从这里https://www.google.com/finance/converter?a=16.6700&from=GBP&to=USD

+0

THX!看起来Google API非常棒! (例如,读者,虽然这从来没有官方太) – MachineElf

+1

看来这个小工具现在已经退休了。我现在收到一个响应错误 – e3matheus

+2

我有同样的问题。他们已将网址更改为http://www.google.com/finance/converter?a=16.6700&from=GBP&to=USD。但是我无法从中得到我需要的回应,所以试图解决它。 –

9

或者您可以使用下列内容:

但第一个是不太稳定熄灭能力非常频繁。在几个月前的第一次交换服务中,我们的生产环境中出现了极端的问题。到目前为止,第二个是稳定的,不会造成任何问题。

+1

因此,我使用它在6 - 7实时部署没有问题。据我们所知,也不应该有机会被关闭。 –

+0

Sougata Pal,是第二可靠吗?将来有机会关闭它吗? – NSPratik

+1

好,没机会。但愿如此。 –

0

自由兑换API从http://mycurrency.net

  • 它是100%免费。
  • 不需要API密钥!
  • API调用频率没有限制。
  • 货币价格每两小时更新一次。
  • 支持json格式。
  • 非常快速和可靠。
  • api地址在这里。它将返回176种货币价格以及国家名称,国家代码,货币名称和货币价格。基础货币是美元。

    http://www.mycurrency.net/service/rates

也有免费的国旗API,你可能还需要。只需更换国家代码即可。

http://caches.space/flags/{countrycode}.png 

例子:

http://caches.space/flags/sg.pngsg

http://caches.space/flags/us.pngenter image description here