【问题标题】:Is is possible to detect the best local currency with PHP without ICU?是否可以在没有 ICU 的情况下使用 PHP 检测最佳本地货币?
【发布时间】:2013-10-15 02:40:47
【问题描述】:

我想向用户显示一个买/卖表格,并且我希望他们的本地货币已经填写好,这样非美国客户就不必在每次访问该页面时都进行更改。

看到How to get the default currency from the PHP Intl ( ICU library ) 让我充满希望,但问题是我只能使用普通 PHP(我无法控制服务器上安装的内容),所以不要有 ICU 可供我使用。

相反,我查看了重复项并尝试了var_dump(localeconv());,但这导致了这个无用的数组:

array(18) {
  ["decimal_point"]=>
  string(1) "."
  ["thousands_sep"]=>
  string(0) ""
  ["int_curr_symbol"]=>
  string(0) ""
  ["currency_symbol"]=>
  string(0) ""
  ["mon_decimal_point"]=>
  string(0) ""
  ["mon_thousands_sep"]=>
  string(0) ""
  ["positive_sign"]=>
  string(0) ""
  ["negative_sign"]=>
  string(0) ""
  ["int_frac_digits"]=>
  int(127)
  ["frac_digits"]=>
  int(127)
  ["p_cs_precedes"]=>
  int(127)
  ["p_sep_by_space"]=>
  int(127)
  ["n_cs_precedes"]=>
  int(127)
  ["n_sep_by_space"]=>
  int(127)
  ["p_sign_posn"]=>
  int(127)
  ["n_sign_posn"]=>
  int(127)
  ["grouping"]=>
  array(0) {
  }
  ["mon_grouping"]=>
  array(0) {
  }
}

所以,鉴于 vanilla PHP 失败了,我无法使用库,这还有可能吗?

【问题讨论】:

    标签: php internationalization currency


    【解决方案1】:

    如果您感兴趣的语言环境未设置为当前语言环境,您必须使用setlocale(). 临时切换到它

    setlocale — Set locale information

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-16
      • 2020-01-22
      • 1970-01-01
      相关资源
      最近更新 更多