C. E.
C. E.

Reputation: 10627

UTF8 problems when using MySQL

I know this has been asked before. But I have exhausted the options given in the answers I can find, so I will ask again and hopefully there is something I have overlooked.

First of all, my files are UTF8-encoded and my XML header (I am using XHTML) declares the page to be UTF8.

Secondly, the first thing I do after connecting to the database is sending the query "SET NAMES utf8".

I have also executed this statement: "SHOW VARIABLES LIKE 'character_set%'" and have set all those variables to utf8.

I have executed SHOW CREATE TABLE table_name on each and every table involved and I have made sure that their character set is utf8.

When I look at the values in the database it looks like UTF8-encoding, with codes beginning with &. This does not feel right, I don't know why they are stored like this. I did try to echo them out on my page with PHP's utf8_decode but this did not work.

What more can I do?

(If my problem is not clear from the title, characters such as ä å and ö do not show up properly in browsers.)

Upvotes: 0

Views: 130

Answers (3)

C. E.
C. E.

Reputation: 10627

OK. This was a PHP issue, as was suggested, and it was derived from my faulty use of htmlentities instead of htmlspecialchars. Be ware when using those functions and utf8 characters! htmlspecialchars is the one you probably want.

Upvotes: 1

BudwiseЯ
BudwiseЯ

Reputation: 1826

When you insert stuff to database, run it through utf8_decode() and when you take the result out of database, run it through utf8_encode().

Also make sure you have UTF-8 encoding or auto detect selected in your browser encoding settings.

Upvotes: 0

Seder
Seder

Reputation: 2763

Have you tried

header('Content-Type: text/html; charset=utf-8'); ?

Upvotes: 0

Related Questions