Strange behaviour of mb_detect_order() in PHP

前端 未结 4 774
梦毁少年i
梦毁少年i 2021-01-05 10:31

I would like to detect encoding of some text (using PHP). For that purpose i use mb_detect_encoding() function.

The problem is that the function returns different re

4条回答
  •  清歌不尽
    2021-01-05 10:34

    Not really. The different encodings often have large areas of overlap, and if your string that you are testing exists entirly inside that overlap, then both encoding are acceptable.

    For example, utf-8 and ISO-8859-1 are the same for the letters a-z. The string "hello" would have an identical sequence of bytes in both encodings.

    This is exactly why there is an mb_detect_order() function in the first place, as it allows you to say what you would prefer to happen when these clashes happen. Would you like "hello" to be utf-8 or ISO-8859-1?

提交回复
热议问题