• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UTF-8 is making me lose my mind

#1
[eluser]Geomancer[/eluser]
I have tried everything, from a lot of websites and this great forum:

-Saving every file to UTF-8
-Using this header:
Code:
header('Content-Type: text/html; charset=utf-8');
-Using the tag:
Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-Every database, table and column is utf8_unicode_ci, as in the database.config file.
-In .htaccess UTF-8 is default.

I have simplified everything and I am usign a single controller/view to make an insert into the DB, with special characters, which show ok in the browser, but are inserted like this: á é í ó ú ñ ¿

If I change the charset in the meta tag to iso, the characters are inserted ok in the db, but they show bad in the browser.

If I utf_encode the strings before inserting, they insert ok, but I will have to decode everything and It is not the point, it should work fine.

I really don't know what else to do, any help will be much appreciated.

Edit: I am using Doctrine, could this be the reason?

#2
[eluser]WanWizard[/eluser]
Check if the page is truely encoded properly. In firefox, via View, Character encoding.
I've seen cases where everything in the application was utf-8, but Apache still generated pages in iso-8859-1.

Check also your database tables. Altough CI thinks (through the config) that they are utf-8, MySQL might think otherwise (depending on how the tables were created).

#3
[eluser]rufnex[/eluser]
you can try to the the charset in the connection before fetch or insert data like that:

Code:
$this->db->simple_query('SET NAMES utf8');

normaly it should be done automaticly by CI (check your settings in config/database.php) and read also
http://dev.mysql.com/doc/refman/5.1/en/c...ction.html

hope it helps!

#4
[eluser]Geomancer[/eluser]
I have found where is the error. I tested everything but Doctrine, believing that it was working ok. Wrong fact.

I made a normal CI query to insert a string, and a normal query to retrieve that string, and they show ok both in the database and the browser.

I will investigate further to detect where Doctrine is doing the wrong encode/decode.

Thanks a lot for your help, you can't know how happy was I when I was answered so fast :-P

Sorry for my english.

#5
[eluser]Geomancer[/eluser]
I fixed it adding the following line in the doctrine config:

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

Now I have to clean the million changes I made in the code, I just have made a new svn branch Tongue

Thanks again to everyone.

#6
[eluser]crikey[/eluser]
I'm having a similar issue with UTF-8 and Greek character conversion, and it's driving me nuts too.

I'm inserting the characters into form fields using the HTML entity codes (e.g. Α &OmegaWink... & Alpha; & Omega; without the space after the &.

The characters seem to insert fine into MySQL - when I look at the record using phpMyAdmin the Greek characters display OK.

But when I retrieve them using ActiveRecord and pass them to the view, they display as

Σ and �

I also have:

- MySQL server config and table config character set and collation settings to use utf8 and utf8_unicode_ci,
- These same settings in my CI database config file,
- Set my .htaccess to use UTF-8 as the default character set (for php, html, js, css files)
- set the meta tag in the view file to Content-type=text/html; charset=utf-8

Is there anything I've missed? I just don't know what else to try.

Thanks
Grant

[SOLVED]
I was using htmlentities() in the view... passing the character set as a parameter to the function fixes the output.

#7
[eluser]Josh Ellis[/eluser]
[quote author="Geomancer" date="1274473818"]I fixed it adding the following line in the doctrine config:

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

Now I have to clean the million changes I made in the code, I just have made a new svn branch Tongue

Thanks again to everyone.[/quote]

I need to say a massive thank you for posting your solution up. It solved my issue and I'm able to continue developing.

I had run in to a similar issue with Zend Framework, but found the issue was actually WAMP Server that I was running. I had to hack the ZF core to fix it.

This issue, however, was related to Doctrine and CI.

Two thumbs up!!!

#8
[eluser]nermion[/eluser]
Hi

thanks alot, this helped me as well, I suspected Doctrine but just didn't know where to look. Your solution worked, so thanks alot!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.