Detect encoding and make everything UTF-8

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

    The interesting thing about mb_detect_encoding and mb_convert_encoding is that the order of the encodings you suggest does matter:

    // $input is actually UTF-8
    
    mb_detect_encoding($input, "UTF-8", "ISO-8859-9, UTF-8");
    // ISO-8859-9 (WRONG!)
    
    mb_detect_encoding($input, "UTF-8", "UTF-8, ISO-8859-9");
    // UTF-8 (OK)
    

    So you might want to use a specific order when specifying expected encodings. Still, keep in mind that this is not foolproof.

提交回复
热议问题