Converting latin1_swedish_ci to utf8 with PHP

后端 未结 2 2319
长情又很酷
长情又很酷 2021-02-20 11:33

I have a database filled with values like ♥•â—♥ Dhaka ♥•â—♥ (Which should be ♥•●♥ Dhaka ♥•●♥) as I didnt specify the collation while creati

相关标签:
2条回答
  • 2021-02-20 11:49

    I would look into mb_detect_encoding() and mb_convert_encoding() and see if they can help you.

    0 讨论(0)
  • 2021-02-20 11:56

    The collation is NOT the same as the character set. The collation is only used for sorting and comparison of text (that's why there's a language term in there). The actual character set may be different.

    The most common failure is not in the database but rather in the connection between PHP and MySQL. The default charset for the connection is usually ISO-8859-1. You need to change that the first thing you do after connecting, using either the SQL query SET NAMES 'utf-8'; or the mysql_set_charset function.

    Also check the character set of your tables. This may be wrong as well if you have not specified UTF-8 to begin with (again: this is not the same as the collation). But make sure to take a backup before changing anything here. MySQL will try to convert the charset from the previous one, so you may need to reload the data from backup if you have actually saved UTF-8 data in ISO-8859-1 tables.

    0 讨论(0)
提交回复
热议问题