msgbartop
PHP源码分析,Zend引擎分析,Web相关技术研究,Web技术分享–左手代码 右手诗
msgbarbottom

31 May 09 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_*系列函数. 明确指出相关的字符集, 从而避免这些问题.

Related Posts:

Tags: , , ,

Reader's Comments

  1. |

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

  2. |

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

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word