views:

382

answers:

3

When I type strange characters like é or ë and store it in a mysql dbase; the character will be converted to: é

It probably will have to do something with my character set. But i don't now where to start. On top of the page i inserted:

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

The collocation of the field in the dbase is: utf8_unicode_ci

Displaying the field in a webpage results in é and ë but displaying them in a textarea results in é

How can i change this?

+2  A: 

There are a two things you can do:

cpharmston
The utf8 functions work. But i think the second option is a better, cause of the global functionality.Where should i change the character set? When i change the collocation of the field, nothing will happen.
blub
See echo's answer below.
cpharmston
+2  A: 

Make sure the collation for the columns, tables and the database are all set to utf8_unicode_ci or utf8_general_ci

You also have to keep in mind, in addition to the meta directive that you already have, to extract and insert entries to and from the database in the same encoding.

Include this line right after you've made the call to connect to the database:

mysql_query("set names 'utf8'");

This will keep the character set properly as UTF-8 state as you manipulate and extract entries in the database.

If you can for next time, have everything in UTF-8 from the very start.

random
the query "set names 'utf8'" influences the whole database?
blub
The query influences things coming in and out of the database. If you don't set the character set, you'll find that even if you have the collation and the page set to UTF-8, the characters won't be delivered correctly.
random
A: 

the mysql_query string works well! :)

to avoid aby encoding problems just set: - meta http-equiv="Content-Type" content="text/html; charset=UTF-8" - utf-8-general-ci on ALL char/text fields of any mysql table you use - mysql_query("set names 'utf8'"); right after th database connection call

cheers

/n.

Nico