How to correct double-encoded UTF-8 strings sitting in MySQL utf8_general_ci fields?

后端 未结 6 1558
感动是毒
感动是毒 2020-12-15 07:42

I have to redesign a class where (amongst other things) UTF-8 strings are double-encoded wrongly:

$string = iconv(\'ISO-8859-1\', \'UTF-8\', $string);
:
$str         


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 08:32

    MySql is charset aware, so you can convert in SQL. But for this case, I would probably prefer to just script it in PHP, as it's a one-off task anyway.

    Keep in mind that columns in MySql have a charset property. The collation is (in theory) orthogonal to the charset. While a utf8_general_ci collation would imply that the charset is utf8, it's not a given. You could in theory mix a utf8 collation with a latin1 encoding (And get garbage as a result).

    If you decide to do this in SQL, look here:

    http://dev.mysql.com/doc/refman/5.0/en/charset-convert.html

提交回复
热议问题