Why use multibyte string functions in PHP?

后端 未结 6 1790
情话喂你
情话喂你 2020-12-16 18:49

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

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 19:02

    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.

    From the Multibyte String Introduction:

    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.

提交回复
热议问题