-2

I have <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> in the header, but it still shows instead of µ. I tried adding AddCharset UTF-8 .php to .htaccess, but it didn't help.

EDIT: if I just put symbol µ in the file, it displays correctly. I get when I try to output it from a database.

good_evening
  • 21,085
  • 65
  • 193
  • 298

2 Answers2

2

If something displays as the � UNICODE REPLACEMENT CHARACTER, that means the document is interpreted in a Unicode encoding (e.g. UTF-8) but the byte sequence at this point is invalid in this encoding.

In other words, your data/file is not UTF-8 encoded. Make sure it's saved as UTF-8, not just declared as such.

If you have problems outputting it from a database, it means the data coming from the database is not UTF-8 encoded. See Handling Unicode Front To Back In A Web App.

deceze
  • 510,633
  • 85
  • 743
  • 889
0

You get this problem because your output actually is not UTF-8, even though you tell the browser that it is. You should fix that problem.

If you fix it by correcting the output so it is proper UTF-8, then your problem will be fixed, because UTF-8 can display this symbol (and any other). If you fix it by changing the charset to an ANSI character set, then you will have output in a codepage that may not support this symbol.

To output it correctly, you can output it as a html entity, either &micro; or &#181;. If you do this now, the symbol will also display correctly, but remember that your actual output is not UTF-8, so if you need another symbol on your page, then you'll have the same problem!

Edit

I see your edit now. If it works with a hard coded character, then the PHP is right, but the fetched data doesn't have the proper encoding. You can solve this by giving your database, table and/or the specific column any of the unicode collations. An alternative method would be to use the function iconv to convert the data from your database to UTF-8 after you query it.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • comment on my answer while you say the same... – Bjorn Jun 30 '13 at 11:09
  • 1
    @Bjorn That's not true. If you look very closely, then you see that instead of a picture of a table, my answer contains some text explaining the problem instead of just specifying a workaround – GolezTrol Jun 30 '13 at 11:12