形式:让用户选择他们的国家(下拉式)并获得货币(php) [英] Form: let user select their country (drop-down) and get the currency (php)

查看:208
本文介绍了形式:让用户选择他们的国家(下拉式)并获得货币(php)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在使用php,mysql和jquery写一个简短的调查(html表单)。我希望用户从下拉列表中选择他们的国家,然后获得正确的货币(服务器端),所以稍后我可以询问引用正确货币的东西。



<对于如何实现这一点,我真的没有清楚的看法。我知道我可以从以下网址找到最新的国家/地区列表: http://www.iso。 org / iso / country_codes / iso_3166_code_lists.htm
我可以创建一个php数组,但是然后?

http://snipplr.com/view/36437/php-country-code --to-html-currency-symbol-list /
看起来不错的代码,但我喜欢用最新的东西。



对于我来说,使用mysql数据库没有任何问题,但是安装插件/扩展(托管不允许它)是一个问题。



是否有人知道一个很好的(也许很容易)实现这个目标的方法吗?

解决方案

PHP Intl的NumberFormatter接受英语作为任何国家的语言。因此,只需使用 en _ 加上您的国家/地区代码即可。

  echo(new NumberFormatter('en_DE',NumberFormatter :: CURRENCY))
- > getTextAttribute(NumberFormatter :: CURRENCY_CODE); // EUR

echo(new NumberFormatter('en_RS',NumberFormatter :: CURRENCY))
- > getTextAttribute(NumberFormatter :: CURRENCY_CODE); // RSD


Currently I'm writing a short survey (html form) using php, mysql and jquery. I want the user to select their country from a drop-down list and then get the right currency (server side) so later on I can ask things referring to the right currency.

I really don't got a clear view on how to achieve this. I know I can find an up to date country list from: http://www.iso.org/iso/country_codes/iso_3166_code_lists.htm I could make into a php array but then?

http://snipplr.com/view/36437/php-country-code--to-html-currency-symbol-list/ Seems nice code, but I like to use something that is up to date.

Its no problem for me to use a mysql database, but it is a problem to install plug-ins/expansions (hosting won't allow it).

Does somebody knows a good (and maybe easy) way to achieve this?

解决方案

PHP Intl's NumberFormatter accepts English as a language for any country. So just use en_ plus your country code.

echo (new NumberFormatter('en_DE', NumberFormatter::CURRENCY))
    ->getTextAttribute(NumberFormatter::CURRENCY_CODE); // EUR

echo (new NumberFormatter('en_RS', NumberFormatter::CURRENCY))
    ->getTextAttribute(NumberFormatter::CURRENCY_CODE); // RSD

这篇关于形式:让用户选择他们的国家(下拉式)并获得货币(php)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆