duanpi5733 2012-10-11 13:53
浏览 47
已采纳

另一种带有重音符号的自动填充情况

We're using this script -- http://jsfiddle.net/6t74T/4/ -- which we learned about in this terrific forum. It uses JQuery autocomplete. The script is working great for our purposes except for diacritics (accented characters). There are a lot of posts in the forum about accented characters, utf-8, etc., but this one is just a little different b/c of how we store our data. Here's an example that illustrates our problem.

If someone adds a person's name to our "people" table, we check the inputted string for accented characters. If there are any we change them to html entities. So "Añosa" gets changed to "A&ntilde;osa". We don't save the data with the accented character because a couple of other processes in our system get seriously kludged up by diacritics. When you view a page that includes this data, it displays correctly because it's simply html. We use PHP and MySQL. Our MySQL tables are set to UTF-8, we use <meta http-equiv="content-type" content="text/html; charset=utf-8" /> in the header of all pages and "accept-charset="UTF-8"" in our form tags. All good.

But, when a name with accented characters displays in an autocomplete list, it appears with the html entities. Instead of seeing "Añosa" in the list which is what we want, we see "A&ntilde;osa". We have tried doing a str_replace on html entities eg., str_replace("A&ntilde;osa", "Añosa", $string), but this results in one of those black diamond with a question mark symbols instead of the accented character. Tried html_entity_decode - also doesn't work. What do we have to do to get this to appear in its accented form in the autocomplete list?

Appreciate any insight, ideas, assistance! Thanks!

  • 写回答

1条回答 默认 最新

  • douche5961 2012-10-11 14:19
    关注

    It sounds to me like you need to decode your names. I have updated this example to show you what I mean. You'll notice that I have 3 "Añosa" names in the list. It sounds like you have "Añosa" in your database, so I am showing you how to decode that with jQuery. You can decode the name server-side when you are writing the names to the list if you want as well.

    I'm not a php guy, but php has a method html_entity_decode() that seems to do what you want.

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

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题