user1286755
user1286755

Reputation: 173

Another accented-character-meets-autocomplete situation

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!

Upvotes: 1

Views: 397

Answers (1)

davehale23
davehale23

Reputation: 4372

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.

Upvotes: 1

Related Questions