Page 1 of 1

How to display japanese kanji from MySQL?

Posted: Sat Oct 04, 2008 8:16 am
by ahounokotoba
I`m new here and new to PHP, sorry if its impolite but I really need an answer to this problem

The point :
1. I made some string with japanese kanji and insert it to my db
2. I insert it via phpmyadmin and it works just fine (it display correctly on phpmyadmin)
3. Upon viewing it using browser the kanji character keep turning into ???
4. I`ve test using a text file (using fopen and fread) and its displayed perfectly
5. I`ve changed the collation (to utf8, sjis and euc) and change the transfer encoding but the problem persists
6. All character but those kanji character displayed correctly

What i wanna know :
1. What`s causing problem here?
2. How do I display those kanji character?

I`ve read many article but nothing seems to works. The only thing I haven`t try is mapping the kanji character which I can`t figure out how to do that and seems lengthy. And to made things worse, the PHP&MySQL manual doesn`t mention about kanji character specifically

Thanks for your attention

Re: How to display japanese kanji from MySQL?

Posted: Sat Oct 04, 2008 8:33 am
by onion2k
Make sure PHP is getting them in the right character encoding with "mysql_query("SET NAMES utf8");" (where UTF8 is whatever the right encoding is for Japanese), then make sure the page is in the same encoding with header("Content-Type: text/html; charset=utf-8");

Re: How to display japanese kanji from MySQL?

Posted: Thu Oct 16, 2008 10:22 pm
by ahounokotoba
^Thanks for the response, but that works only when submitting forms, to display its still the same

by the way here`s some screenshot :
Collation screenshot
Image
Image
PHPMyAdmin view
Image
Website view
Image
Here`s my script (part of the page) :
<?php
$db = mysql_select_db("skaetheater", $connect);
if (!db)
{
die
("sorry dude something error");
}
;

$page = $_GET['page'];
$id = $_GET['id'];
if (!$page)
{
echo '<div id="home">';
$query = "SELECT id, time, subject, post FROM allpost order by time desc limit 0, 1 ";
$read = mysql_query($query);
mysql_query("setnames sjis");
while($content = mysql_fetch_array($read))
{
echo 'Most recent post : '
;
echo ($content['time'])
;
echo '<h3>'
;
echo ($content['subject'])
;
echo '</h3>'
;
echo ($content['post'])
;
}
;
echo '</div>';
?>
my header :
<meta http-equiv="Content-Type" content="text/html; charset=sjis" />
I`m using PHP 5.2.6 and MySQL 5.0.51b

I`m stuck here and can`t think of any other way. Is there any mistake on my script?


Thanks