dongnius85154 2010-08-29 11:49
浏览 26
已采纳

使用php和jquery存储基于html的博客文章时的编码错误

I am writing a code to post html-based blog posts through jquery/ajax to php to amazon s3.

I first urlencode the post with this function from php.js - http://phpjs.org/functions/urlencode:573 then send it to a php which stores the content as is to s3. If i read this file naked, it looks fine with slashed for special characters like " ' ", " " ", etc. which im able to remove with stripslashes.

Now, the problem, if I echo these s3 contents after retrieving with tarzan/CloudFusion library, it echos charactres like ’, “ for " ' ", " " " respectively , but if i send this content through ajax/json encoding it looks all fine.

What exactly am I doing wrong? can someone also shed a light on encodings related in this case or in general.

Thanks for help!

  • 写回答

1条回答 默认 最新

  • douyou4819 2010-08-29 14:00
    关注

    The ’ is typical for a UTF-8 encoded curly singlequote being incorrectly decoded as CP-1252.
    The “ is typical for a UTF-8 encoded curly doublequote being incorrectly decoded as CP-1252.
    Those things are also called "smart" quotes, referring to the ones MS Word is by default using.

    So, somewhere in your layers you are using CP-1252 instead of UTF-8 to display those characters. Most likely you're using Windows and your PHP file is saved/served using CP-1252. Verify the response headers. At least, start adding the following line to the PHP file before any other template text content to force the webbrowser to display those characters using UTF-8:

    header('Content-Type: text/html; charset=UTF-8');
    

    See also:

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

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据