将字符串转换为UTF的最佳方法是什么?

我想知道什么是使用PHP将字符串转换为UTF-8的最佳方式。

以下看起来确定在页面上,但在MySQL中一些字符看起来乱码。

  • 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.
  • 在页面: 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。


    尝试使用mysql_query("SET NAMES 'utf8'") (或dbh->exec("SET NAMES 'utf8'") )来设置连接的编码。


    你应该设置mysql连接的编码。 尝试使用SET NAMES utf8

    链接地址: http://www.djcxy.com/p/25181.html

    上一篇: What is the best way to convert a string to UTF

    下一篇: From collation Modern