PDA

View Full Version : [SOLVED] Accented characters



b3f3
10 Nov 2010, 9:03 PM
Hello everybody,
I've a problem with a JsonStore and accented characters (Im fench).
In the GridPanel, when there must be an accent, the word is simply cut.
I've read this thread but I haven't found the solution.
In my source code, I see <meta http-equiv="Content-Type" content="text/html; charset=utf-8">.
phpMyAdmin show me :
MySQL charset: UTF-8 Unicode (utf8)
MySQL connection collation : utf8_unicode_ci

Can somebody help me ?
Thanks

devnullable
10 Nov 2010, 9:42 PM
Does your server return json with content type application/json?

b3f3
10 Nov 2010, 9:50 PM
how do I know it ? In firebug, I just see the array with data.

devnullable
10 Nov 2010, 10:02 PM
how do I know it ? In firebug, I just see the array with data.
You see array of data where? In response tab in firebug? There's also Headers tab and there you can see Response headers. If your server returns data with content type application/json Firebug show also JSON tab next to Response tab.

b3f3
10 Nov 2010, 10:07 PM
You see array of data where? In response tab in firebug? There's also Headers tab and there you can see Response headers. If your server returns data with content type application/json Firebug show also JSON tab next to Response tab.
I see array in Firebug/Console/Response/.
And to answer you, in Console/Header, I have Content-Type : text/html; charset=ISO-8859-1

devnullable
10 Nov 2010, 10:11 PM
I see array in Firebug/Console/Response/.
And to answer you, in Console/Header, I have Content-Type : text/html; charset=ISO-8859-1
Ok, so the server is not sending with content type application/json then. I had similar problem and after changing to right content type header in server response fixed my problem with some special characters and scandinavian alphabets.

Animal
10 Nov 2010, 10:32 PM
I see array in Firebug/Console/Response/.
And to answer you, in Console/Header, I have Content-Type : text/html; charset=ISO-8859-1


There's your problem. Not the Content-Type itself, but the encoding used by your server.

b3f3
10 Nov 2010, 10:45 PM
There's your problem. Not the Content-Type itself, but the encoding used by your server.
So what do I do? Edit the php server configuration?

Animal
11 Nov 2010, 12:39 AM
Sorry, that I can't help with. I'm a Java/JEE man, I don't know about PHP.

steffenk
11 Nov 2010, 1:08 AM
send a correct header

header('Content-Type: text/html; charset=utf-8');
Ensure you're dealing with utf-8 data in your server classes (eg database connection etc)

devnullable
11 Nov 2010, 2:33 AM
There's your problem. Not the Content-Type itself, but the encoding used by your server.
If the problem is only about the used charset, does it matter which content type is returned from the server? Cause I am pretty sure my problem was fixed by setting the content type to application/json...

steffenk
11 Nov 2010, 2:41 AM
content type - use whatever you want. Charset is important which is settled in the header of the response.

b3f3
11 Nov 2010, 9:38 AM
in Console/Header, I have Content-Type : text/html; charset=ISO-8859-1


There's your problem. Not the Content-Type itself, but the encoding used by your server.


send a correct header
header('Content-Type: text/html; charset=utf-8'); Ensure you're dealing with utf-8 data in your server classes (eg database connection etc)


If the problem is only about the used charset, does it matter which content type is returned from the server? Cause I am pretty sure my problem was fixed by setting the content type to application/json...


content type - use whatever you want. Charset is important which is settled in the header of the response.

Thank you all !!
When I add header('Content-type: text/html; charset=utf-8'); OR header('Content-type: application/json; charset=utf-8'); the result is the same : words are cut when there is an accent.
To connect to MySQL, I use PDO.
In my connection function I have :
$db = new PDO('mysql:host='.$host.';dbname='.$dbName, $user, $pwd);
If I change to :
$db = new PDO('mysql:host='.$host.';dbname='.$dbName, $user, $pwd, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
It's OK now !
(and the header content-type is still text/html; charset=ISO-8859-1)

How to edit the thread title to [SOLVED] ?

steffenk
11 Nov 2010, 10:54 AM
How to edit the thread title to [SOLVED] ?
edit first post in advanced mode

Animal
11 Nov 2010, 11:20 AM
You should set the header to tell the truth about the encoding used.

Otherwise it might start failing when other characters are used. UTF-8 maps to ASCII below codepoint 128 so a lot of people find stuff working by default at first until they start using Unicode codepoints > 128

b3f3
11 Nov 2010, 11:33 AM
You should set the header to tell the truth about the encoding used.

Otherwise it might start failing when other characters are used. UTF-8 maps to ASCII below codepoint 128 so a lot of people find stuff working by default at first until they start using Unicode codepoints > 128

I don't really understand what you say.
Do you say that my issu is not good cause it's not definitif ?

Uberdude
11 Nov 2010, 12:01 PM
It means you should read and understand http://www.joelonsoftware.com/articles/Unicode.html

b3f3
11 Nov 2010, 2:38 PM
It means you should read and understand http://www.joelonsoftware.com/articles/Unicode.html
Thank you, I had already tried to understand the principle of the encoding of characters but I don't. This arcticle is very easy. (the french translation - la traduction franšaise : http://french.joelonsoftware.com/Articles/Unicode.html).
I'll try to be as rigorous as possible in my character handling.