Skip to content Skip to sidebar Skip to footer

JQuery Autocomplete Special Character (Norwegian) Problems

I'm using jQuery's autocomplete function on my Norwegian site. When typing in the Norwegian characters æ, ø and å, the autocomplete function suggests words with the respective c

Solution 1:

The bug (I think):

  • Strtolower() will not lowercase special characters.
  • Therefore, you are not converting capital special characters in your re-write function (Ä Æ Ø Å etc.)

if I understand the code correctly, a query for Øygarden(Notice the capital Ø) would leave the first character in its original form Ø, but you are querying against the urlencode()d form which should be %C3%98

You should use mb_convert_case() specifying UTF-8 as the encoding.

Let me know whether this solves it.

General re-writing suggestions

Your code could be replaced 100% using standard PHP functions, which can handle all Unicode characters instead of just those you specify, thus being less prone to bugs. I think the functionality of your custom rewrite() function could be replaced by

you would then get proper UTF-8 encoded data that you don't need to utf8_encode() any more. It could be possible to get a cleaner approach that way that works for all characters. It could also be that that already sorts whatever bug there is (if the bug is in your code).


Solution 2:

I'm using a similar configuration but with Danish characters (æ, ø and å) and I do not have a problem with any characters. Are you sure you are encoding all characters correctly?

My response contains a | delimited list of values. All values are UTF-8 encoded (that's how they are stored in the database), and I set the content type to text/plain; charset=utf-8 using php's header function. The last bit is not needed for it to work though.

  • Frank

Solution 3:

Thank you for all answers and help. I certainly learned some new things about PHP and encoding :)

But the solution that worked for me was this:

I found out that the jQuery autocomplete function actually UTF-8 encodes and lowercase special character before sending it to the PHP function. So when I write out the arrays of suggest content, I used my rewrite()-function to encode the special characters. So in my compare function I only had to lowercase everything.

Now it works great!


Solution 4:

I had similar problem. solution in my case was urldecode() php function to convert string back to it's original and than send query to db.


Post a Comment for "JQuery Autocomplete Special Character (Norwegian) Problems"