为什么要在PHP中使用多字节字符串函数? [英] Why use multibyte string functions in PHP?

查看:88
本文介绍了为什么要在PHP中使用多字节字符串函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我不理解为什么为什么在处理UTF-8时在PHP中使用mbstring函数真的很重要吗?我在linux下的语言环境已经设置为UTF-8,所以为什么strlenpreg_replace之类的功能默认情况下不能正常工作?

At the moment, I don't understand why it is really important to use mbstring functions in PHP when dealing with UTF-8? My locale under linux is already set to UTF-8, so why doesn't functions like strlen, preg_replace and so on don't work properly by default?

推荐答案

所有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.

这篇关于为什么要在PHP中使用多字节字符串函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆