1

Hello I have a character encoding problem in my application and thought to ask for some help, because I couldn't solve the problem even thought I was given some guidance so here goes: My Ä and Ö characters are shown in the browser as: �

I will also post all what I have done so far trying to solve the problem:

1) Database: I have tried changing the collation of my tables, here are some info what SHOW TABLE STATUS gives for one of my tables:

Name = test_groups
Engine = InnoDB
Version = 10
Row_format = Compact
Collation = utf8_swedish_ci

Database character variables gives:

| character_set_client = utf8
| character_set_connection = utf8
| character_set_database = latin1 (I Wonder is this the cause?)
| character_set_filesystem = binary
| character_set_results = utf8
| character_set_server = utf8
| character_set_system = utf8

2) In apache httpd.conf I have:

AddDefaultCharset UTF-8

3) In my Zend-application application.ini:

resources.view.encoding = "UTF-8"

4) In my firefox 14.0.1 browser

edit->preferences->content->advanced->Default character encoding = Unicode (UTF-8)

5) In my php code meta-tag:

<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

Now here's also few other interesting things: When I look at my page and change from firefox

View->Character encoding->Western (ISO-8859-1)

, the �-characters which came from the MySQL database turn out ok to öä-characters, but the öä-characters that come from my php-code turn into ät-characters.

Another thing when I check the encoding of the data coming from my MySQL-database with

mb_detect_encoding($DATA_FROM_MYSQL_DATABASE)

it outputs UTF-8!! Then lastly if I do in the code:

utf8_encode($DATA_FROM_MYSQL_DATABASE)

and output the result the problem disappears that is �-characters -> öä-characters. So what's going on here x) All help appreciated

jjepsuomi
  • 4,223
  • 8
  • 46
  • 74
  • 1) try in your html file 2) how many characters do you have before that meta tag? Some browsers expect the character encoding info within the first few kilobytes of the document. Using conditional comments for IE classes or fbml markup could push your character encoding info to far behind. – Jan Beck Jul 31 '12 at 16:42
  • Hi Jan Beck here is code from the very beginning of my application: – jjepsuomi Jul 31 '12 at 16:46
  • Should be alright the way it is. Recommend investigating on server-side. – Jan Beck Jul 31 '12 at 17:02

2 Answers2

2

Are you sending SET NAMES utf8 in your PHP as the first query to MySQL ? That could be the cause if not.

SET NAMES indicates what character set the client will use to send SQL statements to the server. Thus, SET NAMES 'cp1251' tells the server, “future incoming messages from this client are in character set cp1251.” It also specifies the character set that the server should use for sending results back to the client. (For example, it indicates what character set to use for column values if you use a SELECT statement.)

SET NAMES utf8 in MySQL? has more detail about how and why.

Community
  • 1
  • 1
Michael Low
  • 24,276
  • 16
  • 82
  • 119
  • Hey, no I'm not using SET NAMES at all at the moment. Just connecting with Zend provided tools and fetching rows and closing the connection – jjepsuomi Jul 31 '12 at 16:51
1

Troubleshoot:

Check your database (with PHPMyAdmin, for instance). Are the characters correctly stored? Or does it seem gibberish?

If the characters in the database are ok, then the problem happens when retrieving. If they are stored incorrectly (as I would guess they are), then the problem is in the "storing".

  1. Check your source code file and verify if they are encoded in UTF-8.
  2. Force mysql connection to use UTF8 (mysqli::set_charset('utf8') or mysql_set_charset('utf8') or PDO: Add charset to the connection string (charset=utf8) )
Tivie
  • 18,864
  • 5
  • 58
  • 77