最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting Currency Information From Country Code in PHP - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 4

Copy 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) ?>
发布评论

评论列表(0)

  1. 暂无评论