0

I get small boxes instead of swedish character å, ä and ö, despite that I'm using UTF-8 everywhere I can think of! I saved the files with UTF-8 without BOM from notepad and the HTML page has meta charset="utf-8" and I changed the table in the database to UTF8_swedish_ci. What have I missed? Preciate some help! Thanks!

EDIT: Would it be better to use latin and save all files in latin instead of UTF8? But could I still use the meta charset="utf-8" in the HTML head?

4
  • 1
    do you see the data correctly in phpMyAdmin? Commented May 1, 2012 at 16:09
  • Yes is't OK in phpMyAdmin. Correctly? Could you explain? Commented May 1, 2012 at 16:13
  • are you doing mysql_query("SET NAMES UTF8") before doing other queries? Commented May 1, 2012 at 16:39
  • Yes! I do a lot of things but nothing works! :( Commented May 1, 2012 at 17:20

2 Answers 2

2

Check what collation you using in MySQL connection? Set right one.

you can change collation for current connection using query: set names utf8 collate utf8_swedish_ci")

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry, but I haven't used PHP for some time, should I add the code above like a query to the table?
@3D-kreativ, yes you execute that command on the same connection as your query (just as you would a query), and before the query.
be sure that in database your data storred correctly. If you insert wrong encoded data, you should export end reimport it.
Now it's working! First I didn't write the query correct, but then with "SET NAMES 'utf8'" it got better! Thanks! :)
1

I believe there are issues in PHP. I was in your situation: database in UTF8, HTML page in UTF8, but the data that i got through mysql_fetch_assoc() was not well encoded (ergo, displaying ? chars like your case).

My solution was to use utf8_encode() and utf8_decode() in my php source to handle the input and output of the database.

See if this solution works for you.

PS. the collation is not the char encoding. Google what collation is. From what I know (not much) is defaulted to swedish_ci because swedish is the most complete in characters. Correct this if I'm wrong.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.