在PHP中将字符串转换为UTF-8的最佳方法是什么?
-
26-10-2019 - |
题
我想知道使用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,HTMLENTITITITY,MB_CONVERT_ENCODING等。
数据库的整理是UTF8_UNICODE_CI,表的Charset为UTF8。
解决方案
尝试使用 mysql_query("SET NAMES 'utf8'")
(或者 dbh->exec("SET NAMES 'utf8'")
)设置连接的编码。
其他提示
您应该将MySQL连接的ALOS设置编码。尝试使用 SET NAMES utf8
不隶属于 StackOverflow