2

i have problems with encoding when using json and ajax. chrome and ie encode umlauts as unicode when jsonifying, firefox and safari returning those utf-8 escaped umlauts like ¼Ã.

where is the best place to give all the same encoding? js / php-get or by writing them to the database.

and i think the next trouble is, when i reload the utf-8 encoded stuff from the db, and write them to the browser and then rewrite them to the db, again via ajax-request a get a real chaos?

can i avoid the chaous? can i handle the encoding in an easy way? pls. help :-)

very important is to also provide security

3
  • It's not clear what you're doing from your question and what went wrong. Perhaps some snippets would help. Commented Aug 31, 2010 at 14:39
  • i even didn't say something went wrong ;-). the thing is, that the browsers jsonify machines giving back strings with different characters for the same input, and the question is: how to handle that, best practice. i think code wont make the problem easier, but one could stick to my code and resolve the problem for my special case - the thing is i am searching for a more reuseable solution. Commented Aug 31, 2010 at 14:56
  • You can set UTF-8 encoding in php.ini and if you are using Apache2 you can use the directive AddDefaultCharset with UTF-8 as Commented Oct 27, 2010 at 16:12

2 Answers 2

1

You must set everything to UTF-8, this means :

Database collation

Table collation

Field collation

Your coding software (example notepad++) encryption.

Sign up to request clarification or add additional context in comments.

1 Comment

Collation is not particularly relevant here, and you certainly don't set encryption in notepad++.
0

Had a similar problem. Maybe you are actually interpreting encoding the wrong way, clientwise. Try setting the frontend encoding before your queries.

<?php
$connection = pg_pconnect("dbname=data");
pg_set_client_encoding($connection, "encoding goes here"); //check enconding aletrnatives on PostgreSQL
$result = pg_query($connection, "SELECT whatever FROM wherever");
//and so on...
?>

I'm a newbie, but it may help. Also won't affect security in anyway if you are already protected against db injection.

Cheers

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.