eugeniu Posted May 12, 2009 Share Posted May 12, 2009 I have a MySQL table in which one column specifically had Japanese characters in it. But when I try to retrieve the content of an entry with Japanese words, I get question marks. For example, "ひらがな" would show up as "????". It shows up just fine when I look at it through phpMyAdmin. I tried changing the field to use utf8_general_ci, utf8_unicode_ci, sjis_japanese_ci, and ujis_japanese_ci, but none of those make a difference. This is the code I use to retrieve the entries: mysql_connect("...") or die(mysql_error()); mysql_select_db("...") or die(mysql_error()); // Get all the data from the "example" table $result = mysql_query("SELECT * FROM kanawords") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Age</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['kana']; echo "</td><td>"; echo $row['answer1']; echo "</td></tr>"; } echo "</table>"; What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/157887-solved-ack-php-returning-question-marks-from-mysql-entries-for-japanese-characters/ Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted May 13, 2009 Share Posted May 13, 2009 If phpmyadmin display correctly the data, then your data is fine and the problem is coming from your script. First set this in your database : Charset : utf8 Collation : utf8_general_ci (ci is for case insensitive) Then you need to tell mysql what charset to use for the connextion like this (right after you connect and select the database) : mysql_query("SET NAMES 'utf8';"); mysql_query("SET CHARACTER SET 'utf8';"); Then you need to tell the browser what charset you use like this : This for the http header (it need to be put before any output even enter or space to work) On each page : header('Content-Type: text/html; charset=utf-8'); And you need to tell the browser again in html because some browser like that : <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> If you are using XHTML instead of HTML it will be more complex depend on how you server your XHTML as text/html or as in XML. Should work fine. Quote Link to comment https://forums.phpfreaks.com/topic/157887-solved-ack-php-returning-question-marks-from-mysql-entries-for-japanese-characters/#findComment-832964 Share on other sites More sharing options...
eugeniu Posted May 13, 2009 Author Share Posted May 13, 2009 That worked marvelous! Thanks! Shame this isn't a default php setting . Quote Link to comment https://forums.phpfreaks.com/topic/157887-solved-ack-php-returning-question-marks-from-mysql-entries-for-japanese-characters/#findComment-832965 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.