Detect encoding and make everything UTF-8

前端 未结 24 2766
暗喜
暗喜 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:18

    php.net/mb_detect_encoding

    echo mb_detect_encoding($str, "auto");
    

    or

    echo mb_detect_encoding($str, "UTF-8, ASCII, ISO-8859-1");
    

    i really don't know what the results are, but i'd suggest you just take some of your feeds with different encodings and try if mb_detect_encoding works or not.

    update
    auto is short for "ASCII,JIS,UTF-8,EUC-JP,SJIS". it returns the detected charset, which you can use to convert the string to utf-8 with iconv.

    
    

    i haven't tested it, so no guarantee. and maybe there's a simpler way.

提交回复
热议问题