Remove non-utf8 characters from string

后端 未结 18 1366
心在旅途
心在旅途 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:57

    Maybe not the most precise solution, but it gets the job done with a single line of code:

    echo str_replace("?","",(utf8_decode($str)));
    

    utf8_decode will convert the characters to a question mark;
    str_replace will strip out the question marks.

提交回复
热议问题