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 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧