Server-side filtering and accented characters
Server-side filtering and accented characters
Hello!
I'm facing an issue with the filtering functionnality of DataTables. It works fine when I use simple latin characters but it makes postgresql crash every time I type an accented letter.
I'm running php5.5 and my website is UTF-8 encoded (other forms work well).
Here's my datatable init, stripped with all the language/column definitions:
doc_table = $('#doc-table').DataTable({
'serverSide': true,
'sortClasses':false,
'dom': 'frtiS',
'scrollY': 200,
'ajax': {
'url':'docs',
'type':'POST',
}
});
In my php script I get the search value with:
$search = Input::get('search')['value']; // Laravel $_POST
If I type 'é' and then log $search, it displays 'é', which doesn't seem right).
The 'htmlentities' method returns 'é' (so it's the right character). If I try to execute a simple pg query with $search as a parameter, it crashes with error:
SQLSTATE[22021]: Character not in repertoire: 7 ERROR: invalid byte sequence for encoding "UTF8": 0xe3 0xa9 0xe3'
I tried several PHP methods to convert/encode/decode back and forth, but no luck so far.
Has anyone faced a similar issue and managed to find a solution?
Thank you
This question has an accepted answers - jump to answer
Answers
Hello!
I still can't find where lies the issue. Does anyone have any idea?
Is your query running é or é? Somewhere along the line it seems to be getting encoded and not decoded. You should see the é if you
utf8_decode()
your$search
variable.Thank you for taking the time to answer me.
The query was running é (and crashed).
Your answer did no directly solved the problem, but it made me realize that my strtolower was causing the issue. I replaced it by mb_strtolower and it works fine without having to use utf8_decode.
Thanks for your time & help!