I want to get the currency code information (for example:USD etc.) from country code.I tried most of methods but I cannot have this data.I had the country code from geolocation. How can I solve this problem and get the currency code?
I want to get the currency code information (for example:USD etc.) from country code.I tried most of methods but I cannot have this data.I had the country code from geolocation. How can I solve this problem and get the currency code?
Share Improve this question edited Nov 25, 2016 at 12:52 Harry 5,7075 gold badges29 silver badges36 bronze badges asked Nov 25, 2016 at 12:01 enesignecienesigneci 3111 gold badge5 silver badges14 bronze badges 2- 1 Here is the data: country.io/currency.json – Emil S. Jørgensen Commented Nov 25, 2016 at 12:03
- 2 see this link:stackoverflow./questions/5741347/… – Suchit kumar Commented Nov 25, 2016 at 12:05
3 Answers
Reset to default 4Copy the object in this page into your code, like this
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"
You can do with this following api its very easy and good
https://restcountries.eu/rest/v1/alpha/in "in" be the country code for india.
Eg with jquery
jQuery.getJSON(
"https://restcountries.eu/rest/v1/alpha/in,
function (data) {
console.log(data.currencies)
}
);
in data: you get almost every information related to country
Here an Array with all Country Information:
<?php $location = unserialize(file_get_contents('http://www.geoplugin/php.gp?ip='.$_SERVER['REMOTE_ADDR'])); print_r($location) ?>