doulangbizhan5160 2011-10-27 09:40 采纳率: 100%
浏览 81
已采纳

PHP不需要的字符删除解

In a description getting characters like "�".

To convert those I tried with utf8_encode() it is converting this charterers to another weird pattern.Also tried with regx and by setting character it didnt work.

Any quick solution to solve the issue?

Thanks.

  • 写回答

2条回答 默认 最新

  • doufuxing8562 2011-10-27 16:39
    关注

    Most likely, your string contains characters encoded using the UTF-8 character set. UTF-8 has some multibyte characters. For example, the Euro symbol is represented in UTF-8 with the three bytes E2, 82, AC.

    But your software is interpreting the string using a one-byte encoding, such as ISO-8859-1. This causes each byte of the 3-byte character to be interpreted as a separate character. E2, for example, is being displayed as â, when it is actually only the first byte of a 3-byte character.

    utf8_encode() is not the solution to this. It takes an ISO-8859-1 encoded string and returns a UTF-8 string. You already have a UTF-8 string.

    You have a couple of options.

    One, fix whatever uses the string so that it expects the string to contain UTF-8. That will properly preserve the characters that are in the string. For example, if you are writing the string as part of a web page, ensure that the webpage's character encoding is UTF-8.

    Two, convert the string to whatever encoding you are actually using. For example, you can convert the string from UTF-8 to ISO-8859-1 with utf_decode(). The disadvantage is that ISO-8859-1 cannot represent as many different characters as UTF-8, so some characters will simply be lost in the decoding.

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

报告相同问题?

悬赏问题

  • ¥15 Python程序,深度学习,有偿私
  • ¥15 扫描枪扫条形码出现问题
  • ¥15 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开