形式:让用户选择他们的国家(下拉式)并获得货币(php) [英] Form: let user select their country (drop-down) and get the currency (php)
问题描述
<对于如何实现这一点,我真的没有清楚的看法。我知道我可以从以下网址找到最新的国家/地区列表: 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屋!