Welcome Guest, Not a member yet? Register   Sign In
Japanese characters - utf-8 encoding problem
#1

[eluser]yosh[/eluser]
Hi, first post, so would just like to say thankyou for making codeigniter available to the public, it's an awesome bit of kit.

Using WAMP, CI and Doctrine and following Buraks fantastic tutorials I am trying to set up my first MVC page, which has worked but all the Japanese characters from mysql display as ? instead of the character ス for example.

In phpmyadmin the characters display properly, tho I did have to change the settings first.

The view file header is set to:
http-equiv="Content-Type" content="text/html; charset=utf-8"

config.php charset is set to utf-8, as are the database settings in doctrine

Had the same problem using php directly until adding mysql_set_charset before the query, as some other posts suggested but I can't see where this would go if this is a solution for codeigniter. Assuming there isn't a setting that's been overlooked somewhere?

Any help greatly appreciated...
#2

[eluser]yosh[/eluser]
My word, what a can of worms character encoding is.

Although I'm certainly no authority on the subject, it looks like the problem stems from wampserver which appears to serve everything up in ISO-8859-1 encoding. It may be a php bug according to a stackoverflow thread that I can't link to.
However, adding one of the lines below, just before a query call in php, works well in a normal php page or php environment.

Code:
mysql_query_charset('utf8')
or
Code:
mysql_query("SET NAMES 'utf8'")

So there must be a way of doing this in the codeigniter framework, but I just don't have the experience to figure out where in the CI files you can add these lines.

Tried everything I could find, trying to override the default settings in apache, php, mysql, htaccess all for nothing. Late last night I stumbled on a thread from these very forums, sorry I missed it.

According to this thread, the doctrine isn't handling the charset encoding and decoding properly and fixed the problem by adding the following line into the doctrine config

Code:
Doctrine_Manager::connection()->setCharset('utf8');

I was just reaching for the cigar at this point, but I'm not sure to which file Geomancer of the other thread is referring to with the "doctrine config". I tried it in the applications/plugins/doctrine_pi.php file that came with the tutorial mentioned in the first post.
This was the first time something happened, but now instead of the questions marks all the Japanese characters display like this "ア, ã"‚ etc.
Did I put the above line in the right file/ place?
If i did, it seems like there's yet another setting that needs changing somewhere.

Any help greatly appreciated.
#3

[eluser]yosh[/eluser]
ahhhhh fixed, sorry

The above line does work, it must be in the right place.

I had earlier added uft8_encode to the view output, and not changed it back.

Sorry for taking up the board space, sometimes writing it down, helps you sort it out.




Theme © iAndrew 2016 - Forum software by © MyBB