dsjgk330337
2012-04-03 17:22 阅读 48
已采纳

处理Charset(用户输入 - > Php - > Mysql再返回)

Please go here to see my problem, its within the card on the left hand side of the page: http://gumonshoe.net/magic/card/?card=258

Apostrophes are getting converted to ascii it looks like from various foreign text formats. I've seen this, but since I'm using american english which is probably the basic defaults I can't reproduce the error to test it.

I figure there's got to be a correct way to be passing the characters around, I just don't know what it is.

The answer I'm looking for will tell me where in this chain things are getting messed up.

User Form on web page for input >>
javascript method >>
php >>
mysql

As far as I can tell this is happening in PHP. Its definitely wrong in the database by the time it gets there.

I'd be most happy with a solution that fixes everything from this point on, rather than a patch to fix what's in the db already as I can just find/replace those instances easily enough.

Thanks for all the help. Searching gave me mixed results, but I couldn't find anything that outright seemed identical to my problem and explained it from the basics up.

Again, thanks much!

Does it have anything to do with this:

mb_internal_encoding
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    duan32342 duan32342 2012-04-03 17:28

    It does not happen in just one place, it always happens in the communication between two ends. That could be in the communication between browser<->php or php<->mysql

    You should make sure to have a charset meta tag in your html header, something like:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    

    That way, your web browser knows what charset to use when posting data to your server (and what charset to use when rendering your page).

    When connecting to mysql, you should make sure that your connection is speaking the same charset at both ends, and that should be the same charset as the web browser is using:

    mysql_query('set names utf8');
    

    Now, you should be fine.

    点赞 评论 复制链接分享

相关推荐