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条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程