简体   繁体   中英

Getting Currency Information From Country Code in PHP

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?

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

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"

这里是包含所有国家/地区信息的数组:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM