2016-11-25 93 views
0

我想从国家代码获取货币代码信息(例如:美元等)。我尝试了大多数的方法,但我不能有这些数据。我有国家代码从地理位置。 如何解决此问题并获取货币代码?从国家代码获取货币信息在PHP

+0

这里是数据:http://country.io/currency.json –

+2

看到这个链接:http://stackoverflow.com/questions/5741347/how-to-get-country-code-and-currency-code -by-ip-address –

回答

1

你可以用这个下面的API做了“在”非常容易和良好的

https://restcountries.eu/rest/v1/alpha/in 是印度的国家代码。

例如,在数据的jQuery

jQuery.getJSON(
"https://restcountries.eu/rest/v1/alpha/in, 
    function (data) { 
    console.log(data.currencies) 
    } 
); 

:你几乎涉及到国家

2

复制对象在此page到代码中每一个信息,这样

var countryCurrencies = { 
    "BD": "BDT", 
    "BE": "EUR", 
    "BF": "XOF", 
    ... 
    "UA": "UAH", 
    "QA": "QAR", 
    "MZ": "MZN" 
} 
//get your country code 
var countryCode = "ma"; //For example 
var currency = countryCurrencies.hasOwnProperty(countryCode.toUpperCase()) ? countryCurrencies[countryCode.toUpperCase()] : "Unkonw"; 


//The result : curreny = "MAD" 
+1

这是一个更优化的答案。货币代码不会经常更改。将表嵌入代码比远程方法更好。 –

0

这里的与所有国家信息阵列:

<?php $location = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'])); print_r($location) ?>