douchen5971 2013-08-13 10:01
浏览 28

在PHP中使用重音字符

I am trying to upload text into my database. I keep getting encoded text when user input certain characters. For example, if the user inputs "Jalapeño" I end up getting "Jalape%C3%B1o" in my database.

I know this is because the "ñ" is being read as "%C3%B1"...

I am not exactly sure how to go about converting all of the potential accented characters, I have looked at rewurldecode and others, but am wondering if there is a quick solution here. Any recommendations would be wonderful. Thank you!

  • 写回答

2条回答 默认 最新

  • douhengdao4499 2013-08-13 10:04
    关注

    Make sure your database uses the right character set and collation (usually you'll want UTF-8). Also make sure you you set the connection character set and sent the right headers.

    e.g. mysql:

    mysql_connect();
    mysql_set_charset("utf8");
    header('Content-Type: text/html; charset=utf-8');
    

    You could also use htmlentities to convert the special characters into HTML entities, but you'll still need to make sure your database collation and connection settings are correct.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入