Press "Enter" to skip to content

PHP受locale影响的函数

项目遇到一个问题,不同的服务器运行结果不同.
究其原因, 是因为使用了和locale相关的一些函数, 并且服务器locale不同所致, 总结了这些函数如下:

字符串相关:

strtoupper 转换大写
strtolower 转换小写
ucfirst 首字大写
sprintf 其中一部分格式化有关
ctype_alpha 检测是否全字母
ctype_alnum 检测是否全数字
ctype_cntrl 检测是否全控制字符
ctype_upper 检测是否全大写
ctype_lower 检测是否全小写

日期相关:

gmstrftime 根据区域设置格式化 GMT/UTC 时间/日期
strftime 根据区域设置格式化本地时间/日期
strptime 处理strftime返回的时间为数组

货币相关:

money_format 把数字以货币格式格式化

最后就是locale相关函数:

setlocale 设置local
localeconv 获得数字相关的locale信息

做为一个国内的PHPer来说, 难免会遇到很多要和locale相关的问题, 这个时候,最好使用mb_*系列函数. 明确指出相关的字符集, 从而避免这些问题.

11 Comments

  1. dna
    dna March 15, 2023

    so much great information on here, : D. dna24bet

  2. ltobet
    ltobet July 8, 2022

    ltobet
    Good I appreciated your work very thanks

  3. Hey! Someone in my Myspace group shared this website with us so I came to give it a look.
    I’m definitely enjoying the information. I’m bookmarking and will be
    tweeting this to my followers! Fantastic blog and outstanding design.

  4. flyfree
    flyfree August 16, 2013

    您好,请教一个问题,php里也有locale类,不知这个类的使用是怎样的,对输入输出是否有影响

  5. laruence
    laruence May 31, 2009

    比如, 字符串A(UTF8,Upper Case)来自数据库, 要比较的数据B(UTF8,内容和A相同)来自脚本.
    这样,在不同的server下, strotoupper(B)和A做比较就会有不同的结果.

  6. kiki
    kiki May 31, 2009

    请教strtoupper这样的函数会出现哪些不同呢?

Comments are closed.