doupinwan0563 2018-07-12 10:53
浏览 136

PHP money格式在不同的服务器上返回带/不带货币前缀的字符串

My client has 2 servers, staging and live. They have different PHP versions (I know - they provide them that way). I have this code:

setlocale(LC_MONETARY, 'en_GB');
$product = wc_get_product( $product_id );
if ($product->get_price()){
   return (string) money_format('%i', $product->get_price());
}

On the staging server it returns prices formatted like this: 'GBP 10.00' However on live it returns prices without the GBP prefix, just '10.00'

On both servers when run: locale -a | grep en_GB I get:

en_GB
en_GB.iso88591
en_GB.iso885915
en_GB.utf8

Staging server is running PHP 5.6.21 on Linux version 2.6.32-696.18.7.el6.x86_64 (mockbuild@c1bl.rdu2.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Thu Jan 4 17:31:22 UTC 2018

Live is running PHP 5.3.28 on Linux version 4.9.96mtv23 (ci_slave@cislave73-git.mtsvc.net) (gcc version 4.7.2 (Debian 4.7.2-5) ) #1 SMP Tue May 15 14:22:40 PDT 2018

Additional discovery... I've now found that the issue occurs when this code is called many times from a loop (i.e. when I am returning a lot of products). If it is just called once during the execution of the php script (returning a single product) it works!

  • 写回答

1条回答 默认 最新

  • dongmou2389 2018-07-12 11:02
    关注

    You should set locale with utf-8 charset:

    setlocale(LC_MONETARY, 'en_GB.utf8');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧