Page 1 of 1

PHP/MySQL output UTF8 Asian characters as question marks?

Posted: Fri Jun 12, 2009 5:02 pm
by JAB Creations
PHP and MySQL are outputting question marks in place of the Asian characters in my MySQL database. I've set the collation to utf8_general_ci. I redid my site's front page and the content is stored in the PHP file along with 27 total different languages all of which display correctly. The files in question are all saved without a BOM (byte order mark) as UTF-8. I can see the Asian characters displaying just fine in phpMyAdmin so I presumed I was missing something in regards to MySQL however I have watched the MySQL queries (with Tail for real time display of all MySQL queries on my PC) and I haven't noticed any syntax that seems unfamiliar...I also tried the utf8_decode function and that didn't do anything. So I'm not really sure what to do at this point other then continue to comb through blog postings, thoughts please?

Re: PHP/MySQL output UTF8 Asian characters as question marks?

Posted: Fri Jun 12, 2009 11:20 pm
by requinix
Four things to check with text encoding problems:
1. The database table is in the right encoding
2. The PHP file is in the right encoding
3. The HTML output is in the right encoding (check headers and <meta> tags; Firefox's Page Info dialog is very handy for this)
4. The font being used (in the HTML) has those characters

Re: PHP/MySQL output UTF8 Asian characters as question marks?

Posted: Sat Jun 13, 2009 5:04 pm
by JAB Creations
The collation of the columns of the table and the table itself is utf8_general_ci.

The PHP files handling the MySQL connection, includes, etc are all UTF-8 without a DOM (Byte Order Mark).

The XML output is encoded as UTF-8.

The font-family is serif which is the same font that the working display of Asian characters is displayed as.

I am just going to manually try to recheck everything I suppose.

Re: PHP/MySQL output UTF8 Asian characters as question marks?

Posted: Sat Jun 13, 2009 5:37 pm
by Eran

Re: PHP/MySQL output UTF8 Asian characters as question marks?

Posted: Sat Jun 13, 2009 5:58 pm
by JAB Creations
AWESOME!

Thanks pytrin!

I added this in addition to the time zone command in the PHP file that allows me to set the time zone...

Code: Select all

mysql_query("SET time_zone = '-4:00';");
mysql_query("SET CHARACTER SET 'utf8';");
Thankfully the live server I'm using only required that line as well. I tried both and I think it'll stick with the first line.

I've had a real tug-of-war with trying to figure out if it was PHP or MySQL and that thread completely clarifies things. Thanks again! :drunk:

Re: PHP/MySQL output UTF8 Asian characters as question marks?

Posted: Sat Jun 13, 2009 11:57 pm
by JAB Creations
After some testing (and fixing of) Version 2.9's CMS I discovered I needed that second MySQL query to get $_POST of Unicode characters to work correctly...

Code: Select all

mysql_query("SET time_zone = '-4:00';");
mysql_query("SET CHARACTER SET 'utf8';");//GET and POST
mysql_query("SET NAMES 'utf8';");//POST