Detect encoding and make everything UTF-8

前端 未结 24 2372
暗喜
暗喜 2020-11-22 03:03

I\'m reading out lots of texts from various RSS feeds and inserting them into my database.

Of course, there are several different character encodings used in the fee

24条回答
  •  盖世英雄少女心
    2020-11-22 03:16

    The most voted answer doesn't work. Here is mine and hope it helps.

    function toUTF8($raw) {
        try{
            return mb_convert_encoding($raw, "UTF-8", "auto"); 
        }catch(\Exception $e){
            return mb_convert_encoding($raw, "UTF-8", "GBK"); 
        }
    }
    

提交回复
热议问题