Sorting with international characters?

Sorting with international characters?

MrAdamMrAdam Posts: 7Questions: 0Answers: 0
edited June 2011 in General
Hey there. I had to add the following at the end of my external search.php file to get

Replies

  • MrAdamMrAdam Posts: 7Questions: 0Answers: 0
    edited June 2011
    Seems like some of my text got lost..
    I had to write the following to get DataTables to even fetch columns containing æøå:

    function encode_items(&$item, $key) {
    $item = utf8_encode($item);
    }
    array_walk_recursive($output, 'encode_items');

    echo json_encode( $output );

    My other problem now, is that I can't filter according to æøå.
    As soon as I write æø or å, it tells me nothing can be found.
    Database is UTF-8, all files is UTF-8.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Are you telling the browser that it is a UTF-8 file using a meta tag?

    Allan
  • MrAdamMrAdam Posts: 7Questions: 0Answers: 0
    Yes. I set both the file encoding, and the meta tag in all my files. As I said, I got it working with fetching by using UTF8_encode. But I can't get filtering to work..
  • MrAdamMrAdam Posts: 7Questions: 0Answers: 0
    The database is UTF-8, and the chars are stored as æø and å.
    I think its due to DataTables encoding the filter-input or something.
    Im not that experienced with this, which is why I am asking for help.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    DataTables doesn't do any character conversation at all and will work with whatever strings you give it. Can you give us a link please so I can see it in action?

    Allan
  • MrAdamMrAdam Posts: 7Questions: 0Answers: 0
    http://intranetvaerket.dk/intranet/brancheportal.php
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited June 2011
    [code]
    "bServerSide": true,
    "sAjaxSource": "search.php"
    [/code]

    You are using server-side processing, so the filtering is done entirely on the server-side. This is the search parameter which is being sent when searching for "ø":

    > sSearch=%C3%B8

    So the first thing I would suggest is echoing out $_POST['sSearch'] in the 'search.php' script and make sure that it is decoded as "ø" by the server-side. If it is, then I would next suggest echoing out the SQL that is run against the server and try running it through something like phpMyAdmin or whatever. If not, then the question is, why isn't PHP decoding a UTF8 character and what is it decoding it as...

    Allan
  • MrAdamMrAdam Posts: 7Questions: 0Answers: 0
    Thank you. I thought it was handled by the javascript.
    Ill take a look at it now.
  • MrAdamMrAdam Posts: 7Questions: 0Answers: 0
    I got it working by adding "$_GET['sSearch'] = utf8_decode($_GET['sSearch']);"
    To the PHP script.

    Thanks for the quick responses and your help.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Great to hear, and thanks for posting back to the solution. I'll remember that one myself - I'm sure it will come in useful!

    Regards,
    Allan
This discussion has been closed.