Welcome Guest, Not a member yet? Register   Sign In
string encoding…
#1

[eluser]K.OS[/eluser]
hi there,

i have little problem with string escaing in code igniter, but i am not really sure if the problem can be found in ci at all…

i created an app using ci to read a given database, its basically just an interface to the data of an existing project, so changing the database is not an option.

this is what happens when i query the db which stores location based data like addresses:
the database outputs a string like "sample road 68" or "Görlitzer Straße 23". the first string was never a problem, but second one is, the website stores strings utf8 encoded in the database, so even if the table is set to store utf8, it will be saved as an utf8 decoded string…

so, when i query the db, i have to do an utf8_decode on "Görlitzer Straße" to get Görlitzer Stra??e… and because i have to output the data as a json string, i do an json_encode… but whenever i have this ?? character in my string, json_encode resets the stored string to null.

i have no clue, why utf8_decode works on some characters of the string, like the german umlaute but not with "sz" char(ß)…

the website that creates this data is done in symfony and symfony decodes and encodes the data correctly, but i have no idea how this is done.

what could cause a problem like this? is my database configuration wrong?

anyone, any idea how to solves this problem?

ps. i asked the symfony dev and he told me that he is not doing anything special with that data, it just outputs correctly in simfony…
#2

[eluser]Phil Sturgeon[/eluser]
What is your database encoding set to, and what is your database config file set to?
#3

[eluser]K.OS[/eluser]
this is what db config looks like
Code:
$db['dev']['dbprefix'] = "";
$db['dev']['pconnect'] = TRUE;
$db['dev']['db_debug'] = TRUE;
$db['dev']['cache_on'] = FALSE;
$db['dev']['cachedir'] = "";
$db['dev']['char_set'] = "utf8";
$db['dev']['dbcollat'] = "utf8_general_ci";

and the encoding of the datebase is set to utf8 but the data saved into this table is utf8 decode again anyway… dont know why…
#4

[eluser]Jeroen Brussich[/eluser]
Do you serve the page as utf-8 encoded?
Code:
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />    
</head>
#5

[eluser]Phil Sturgeon[/eluser]
There are loads of different kinda of UTF-8. Make sure your database AND your config are both set to utf8_unicode_ci as utf8_general_ci is a smaller, lazier, not quite as useful version.
#6

[eluser]K.OS[/eluser]
@Jeroen
i do not output html code, the resulting data will be printed as a json string which is unicode anyway…

@phil
this kind of helped to understand whats going on in the database… i played with the encoding setting in my sql application and set it to UTF-8 Unicode via Latin 1 and for the first time i see the data correctly encoded.

how can i set the same encoding in code igniter and what does "UTF-8 Unicode via Latin 1" mean anyway?




Theme © iAndrew 2016 - Forum software by © MyBB