dou760663 2012-08-18 10:58 采纳率: 100%
浏览 36
已采纳

PHP - 字符编码问题 - 必须缺少某些东西

In my PHP page, product descriptions are showing up with the infamous £ issue.

Aha! I thought - I must remember to move the entire website over to UTF-8. So I:

  • Specified in both the mysql_set_charset('utf8'); and the array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") command. I'm migrating the website over to PDO - so still in a transitional process. The actual part of the website where the product description is saved and read both use the new PDO method.
  • Specified ini_set('default_charset', 'utf-8'); at the start of my header.php page.
  • Specified <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> in the head tag of the HTML page. I verified that there were no caching issues by checking that it appears.
  • Changed the collation of the products table to utf8_general_ci.

But the error still occurs. It even occurs on new products and when I edit the product to remove and re-add the pound sign. Is there anything I'm missing?

  • 写回答

2条回答 默认 最新

  • duai5344 2012-08-18 22:33
    关注

    I found the problem. I was throwing htmlentities() onto the strings for security when I was echoing them to the browser. I should have thrown:

    htmlentities($string, ENT_COMPAT | ENT_HTML401, "UTF-8"); to rectify this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题