Welcome Guest, Not a member yet? Register   Sign In
UTF-8
#1

[eluser]Tanax[/eluser]
Hi again!

I must first say that this forum is great with responses! I recieved response on my first issue within .. short time(too lazy to go back to the thread and check Big Grin).

With that said,
I have a problem with the charset.

To tell you a bit of information about the project I'm working on, I'm actually converting an old site of mine, into using codeigniter.
So the problem is, I'm storing categories in db, and listing them on the site by a db->get and the foreach the results.

Worked GREAT on the original site.
However, now with the codeigniter implemented, it doesn't appear to be working with å ä ö chars(swedish letters), which is strange, because it worked like a charm on the original site.

Anyone know a solution to this?
Thanks in advance!
#2

[eluser]i_like_ponies[/eluser]
Do you think it's an issue of the mysql client not retruning the correct character set or that the php response isn't setting the correct character set (mine defaults to: ISO-8859-1)?

Most likely you'll have to do something like this at the beginning of your controllers:

Code:
$this->output->set_header("Content-type: text/html; charset=UTF-8");

Not sure if that works since I haven't tested it, but most likely your web server isn't output the correct character set headers.
#3

[eluser]Tanax[/eluser]
I don't think it has anything to do with mysql at all since the mysql worked great on the original site, so it's nothing with the database(cause it's the same database).
However it could be a setting in this mysql class that I've overlooked.

The weird thing is that the HTML pages are
Code:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

and if I change the charset THERE to UTF-8, the categories menu(the one which is retrieving the list from the db) gets corrected and prints the åäö chars, while the åäö chars inside the templates(which is NOT retrieved from the db) gets screwed up :S
#4

[eluser]Mackstar[/eluser]
You should check your database collation if it is in UTF-8 then you need to use

$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

etc...

Cheers

Richard
#5

[eluser]Mackstar[/eluser]
Sorry about the multiple posts... Also check your apache conf file which could have the default charset or language set in there, you can comment it out...

Cheers

Richard
#6

[eluser]Colin Williams[/eluser]
Same encoding in. Same encoding out. No problems.

These are the basics! Learn them first!
#7

[eluser]Mackstar[/eluser]
I appreciate what you are trying to say Colin, this is generally the case.

But I have seen numerous server setups that blow this basic out of the water. Some being even a standard install of apache which defaults to a particular character set, also php.ini set ups which force post variables into a different encoding...

So I would look into those first as there is a good chance the environment maybe the issue...
#8

[eluser]Tanax[/eluser]
This is my categories table:
Code:
CREATE TABLE IF NOT EXISTS `categories` (
  `cat_id` tinyint(3) NOT NULL AUTO_INCREMENT,
  `cat_desc` varchar(255) NOT NULL,
  `cat_order` tinyint(3) NOT NULL,
  `cat_name` varchar(28) NOT NULL,
  `cat_visible` tinyint(3) NOT NULL,
  PRIMARY KEY (`cat_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

Seems as the charset is latin1. I also checked the collation, and it's latin1_swedish_ci.
Should I change this?

Or should I change something in CI?

Also; Colin- what do you mean?

Thanks!
#9

[eluser]Mackstar[/eluser]
My Advice when working in another language is to go completely UTF-8,

rebuild your mysql tables with the collation utf8_general_ci and all fields to be so also.. The you just add the lines to your db config and it should get the data out of the database correctly.

$db[‘default’][‘char_set’] = “utf8”;
$db[‘default’][‘dbcollat’] = “utf8_general_ci”;

But in your case you dont know if it is the database data or the page parsing that is wrong.

If you have <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> in your html it is being set somewhere in your CI app, check your headers/footers, or search for ISO-8859-1 in your app to find the culprit.

You could try to juggle the char encoding selection in your browser and see if you get the hoped for output, in which case the meta tag may well be your culprit.


If you did want to play with your db connection you could try

$db[‘default’][‘char_set’] = “latin1”;
$db[‘default’][‘dbcollat’] = “latin1_swedish_ci”;

I do a lot of development in Japanese and have found a strict utf-8 only environment has made things much easier.

Best of luck
#10

[eluser]vitoco[/eluser]
Another important thing , is to save the files ( controllers, models , helpers and views ) in UTF8 ( without BOM ) , cause this may cause wrong output if you process string, and can even change the page charset encode




Theme © iAndrew 2016 - Forum software by © MyBB