Why use multibyte string functions in PHP?

后端 未结 6 1785
情话喂你
情话喂你 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 18:59

    People here don't understand UTF-8.

    You do not need to use UTF-8 aware code to process UTF-8. For the most part.

    I've even written a Unicode uppercaser/lowercaser, and NFC and NFD transforms, using only byte-aware functions. It's hard to think of anything more complicated than that, that needs such delicate and detailed treatment of UTF-8. And yet it still works with byte-only functions.

    It's very rare that you need UTF-8 aware code. Maybe to count the number of characters, or to move an insertion point forward by 1 character. But actually, even then your code won't work ;) because of decomposed characters.

    But if all you are doing is replacements, finding stuff, or even parsing syntax, you just need byte-aware functions.

    I'll explain why.

    It's because no UTF-8 character can be found inside any other UTF-8 character. That's how it is designed.

    Try to explain to me how you can get text processing errors, in terms of a multi-byte system where no character can be found inside another character? Just one example case! The simplest you can think of.

提交回复
热议问题