views:

36

answers:

2

hey all together,

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

A: 

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

Database collation

Table collation

Field collation

Your coding software (example notepad++) encryption.

Dominique
well, thanks. actually thats all on utf-8.
helle
[Collation](http://en.wikipedia.org/wiki/Collation) is not particularly relevant here, and you certainly don't set [encryption](http://en.wikipedia.org/wiki/Encryption) in notepad++.
Artefacto
A: 

Hey,

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

misterte