Forum Moderators: coopster

Message Too Old, No Replies

PHP UTF-8 problem

         

alexey9

4:50 pm on Sep 21, 2007 (gmt 0)

10+ Year Member



Hello guys,

I'm currently building multilanguage website and I have a strange problem when I try to print messages in another languages. For example, when I get russian translations from MySQL database and trying to print them with PHP, browser shows just "?" instead of the message in russian.

My MySQL tables are UTF-8 by default (character set is set to "UTF-8 Unicode" and collation is set to "utf8_general_ci").

My HTML pages have also metatag to show UTF-8:

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

I've googled for it, and found one advice. I've added "mysql_query("SET NAMES utf8");" into my PHP script before other MySQL queries instead of "?" I get a lot of ugly characters in the browser now like "&#208;”&#208;&#190;&#208;±&#208;°&#208;&#178;&#208;&#184;&#209;‚&#209;&#338; &#208;&#188;&#208;µ&#209;&#129;&#209;‚&#208;&#190; &#208;&#180;&#208;»&#209;&#143; &#208;&#191;&#208;&#190;&#209;&#129;&#208;µ&#209;‰&#208;µ&#208;&#189;&#208;&#184;&#209;&#143;".

I think it's PHP/MySQL problem, not browser or HTML. I wonder how can I fix it?

eelixduppy

3:16 am on Sep 29, 2007 (gmt 0)



Try setting Content-Type with header() and see what you get. If this doesn't work try it without the mysql_query("SET NAMES utf8");. What you are getting is the htmlentities for the characters; I'm not exactly sure why, though, from what I can see. You can try html_entitiy_decode [us3.php.net] however that just goes around the problem and doesn't fix it.

alexey9

3:08 pm on Sep 29, 2007 (gmt 0)

10+ Year Member



Thanks for reply. I've added header to PHP script and it works now. :)

eelixduppy

4:02 pm on Sep 29, 2007 (gmt 0)



Get you got everything resolved now. Sorry for the delayed response.