doulin4844 2012-11-18 06:40
浏览 52
已采纳

如何在codeigniter中解码utf-8字符?

I'm developing a site with codeigniter that support multilanguage. When a user search with their native language I got the first result when I paginate the result the character is not decoding.

This is the url which is used to paginate.

enter image description here

When I print the uri segment I got %E0%B4%AE

I tried the url encode and url decode that time I got a different charecter like à´®

Can any one tell me how can I decode this type of charecterset?

  • 写回答

1条回答 默认 最新

  • doutany76678 2012-11-18 06:43
    关注

    While urldecode is what you should be using, the reason that you are getting the wrong output printed is probably because the output page's encoding hasn't been set to UTF-8, and is thus defaulting to ISO-8859-1. Hence, while the characters have been decoded correctly by PHP, the browser then interprets the characters in the wrong encoding, resulting in incorrect display.

    To fix the problem, send a charset in the Content-type header before any output like so:

    header('Content-type: <type>; charset=utf-8');
    

    If your output page is HTML, you could alternatively use this tag in the head:

    <meta charset="utf-8">
    

    If you take the second option, be sure to place the tag as early as possible in the head, as browsers do not scan past the first 1024 bytes of the page for this declaration.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记