且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么要在PHP中使用多字节字符串函数?

更新时间:2022-06-23 22:49:25

所有PHP

All of the PHP string functions do not handle multibyte strings regardless of your operating system's locale. That is why you need to use the multibyte string functions.

来自多字节字符串介绍:

当您操纵(修剪,分割,拼接等)编码为 多字节编码,您需要使用特殊功能,因为两个或 在这样的情况下,更多连续字节可能表示单个字符 编码方案.否则,如果您应用非多字节感知字符串 函数的字符串,它可能无法检测到开始或 多字节字符的结尾,并以损坏的垃圾结尾 最有可能失去其原始含义的字符串.

When you manipulate (trim, split, splice, etc.) strings encoded in a multibyte encoding, you need to use special functions since two or more consecutive bytes may represent a single character in such encoding schemes. Otherwise, if you apply a non-multibyte-aware string function to the string, it probably fails to detect the beginning or ending of the multibyte character and ends up with a corrupted garbage string that most likely loses its original meaning.