duanha3539 2012-01-27 11:32
浏览 32
已采纳

用£替换£

I am trying to replace £ with £ and it did not work.

I've tried:

echo str_replace("£", "£", "£3 Discount Discount");

I have also tried html_entity_decode which also did not work.

  • 写回答

4条回答 默认 最新

  • dsy6639 2012-01-27 12:30
    关注

    This is an issue with trying to display UTF-8–encoded data as non–UTF-8. You need to make sure that all character encodings are consistent, and if not then you're converting between them appropriately. The easiest way is to ensure that absolutely everything is in UTF-8. This includes:

    • The data that's saved in the database (MySQL's character set / collation)
    • The client connection to the database (Using SET NAMES UTF-8)
    • The output to the browser (header('Content-Type: text/html; charset=utf-8');)
    • The PHP script containing the code (yes, this sometimes has an impact)

    I would first suggest checking that there isn't any mojibake in your database (e.g. using phpMyAdmin or command-line client), before checking the character sets above. If you find that the database actually contains £, then I would suggest applying the same logic above to any input mechanism to the database (including character encoding of HTML forms).

    (Note: I've assumed MySQL throughout this answer.)

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

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP