简体   繁体   English

在PHP中从国家/地区代码获取货币信息

[英]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. 我想从国家/地区代码中获取货币代码信息(例如:USD等)。我尝试了大多数方法,但无法获得此数据。我从地理位置获得了国家/地区代码。 How can I solve this problem and get the currency code? 如何解决此问题并获取货币代码?

You can do with this following api its very easy and good 您可以使用以下api来完成此操作

https://restcountries.eu/rest/v1/alpha/in "in" be the country code for india. https://restcountries.eu/rest/v1/alpha/in"in “是印度的国家/地区代码。

Eg with jquery 例如与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) ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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