Remove non-utf8 characters from string

后端 未结 18 1846
心在旅途
心在旅途 2020-11-22 11:56

Im having a problem with removing non-utf8 characters from string, which are not displaying properly. Characters are like this 0x97 0x61 0x6C 0x6F (hex representation)

18条回答
  •  我在风中等你
    2020-11-22 12:36

    You can use mbstring:

    $text = mb_convert_encoding($text, 'UTF-8', 'UTF-8');
    

    ...will remove invalid characters.

    See: Replacing invalid UTF-8 characters by question marks, mbstring.substitute_character seems ignored

提交回复
热议问题