我想知道使用PHP将字符串转换为UTF-8的最佳方法是。
以下内容在页面上看起来不错,但在MySQL中,某些字符看起来很乱。
UPGRADE EVENT – New Mazda2 from £124.99 per month. Representative 0% APR over 3 years. Min 50% deposit required. Call xxxxxxxxxxxx for test drive, info or Ts&Cs.
UPGRADE EVENT - New Mazda2 from £124.99 per month. Representative 0% APR over 3 years. Min 50% deposit required. Call xxxxxxxxxxxx for test drive, info or Ts&Cs.
我看过iconv,mb_string,html_entity_decode,htmlentities,mb_convert_encoding等。
数据库排序规则是utf8_unicode_ci,表格的字符集是utf8。
答案 0 :(得分:4)
尝试使用mysql_query("SET NAMES 'utf8'")
(或dbh->exec("SET NAMES 'utf8'")
)来设置连接的编码。
答案 1 :(得分:1)
你应该设置mysql连接的编码。尝试使用SET NAMES utf8