可以在没有ICU的情况下使用PHP检测最佳本地货币


Is is possible to detect the best local currency with PHP without ICU?

我想向用户显示一个买入/卖出表格,我希望他们的当地货币已经填写完毕,这样非美国客户就不必在每次访问页面时都更改此表格。

看到如何从 PHP 国际(ICU 库)获取默认货币,我充满希望,但问题是我只能使用普通 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) {
  }
}

所以,鉴于普通PHP让我失败并且我无法使用库,这仍然可能吗?

如果您感兴趣的区域设置未设置为当前区域设置,则必须使用 setlocale(). 暂时切换到它

设置区域设置 — 设置区域设置 信息