What is the best way to convert a string to UTF

I am wondering what the best way to convert an string into UTF-8 using PHP is.

The following looks ok on the page, but in MySQL some characters are looking garbled.

  • 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.
  • ON PAGE: 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.
  • I have looked at iconv, mb_string, html_entity_decode, htmlentities, mb_convert_encoding etc..

    The database collation is utf8_unicode_ci and the tables' charset is utf8.


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


    You should alos set encoding of mysql connection. Try to use SET NAMES utf8

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

    上一篇: 有没有一个相当于C#的DateTime.TryParse()的Python?

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