【发布时间】:2011-08-14 15:27:12
【问题描述】:
我想知道使用 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.
我看过 iconv、mb_string、html_entity_decode、htmlentities、mb_convert_encoding 等。
数据库排序规则是 utf8_unicode_ci,表的字符集是 utf8。
【问题讨论】:
-
mb_convert_encoding 为我工作,你面临什么问题?
-
@Tobiask: mb_convert_encoding(htmlentities(html_entity_decode($string), ENT_QUOTES, 'ISO-8859-1'), "UTF-8", "UTF-8");是我用的
标签: php mysql encoding utf-8 string-conversion