making Japanese text display in browser when coding php/html

AKA Geek talk - discuss technology in general; this may or may not relate to Japanese
Post Reply
User avatar
Dehitay
Posts: 1011
Joined: Fri 09.08.2006 8:36 pm
Native language: English
Gender: Male
Location: San Antonio, Texas, USA

making Japanese text display in browser when coding php/html

Post by Dehitay » Sat 07.18.2009 1:28 pm

I figured out that I could get Japanese text into a database by changing the collation and I was proud of myself for that, but now I can't figure out how to get the database to spit that Japanese text back into a browser when using php or html. There's a section in my php file that looks like this:

echo $row["jap"] . "<br>";
echo "青い<br>";
?>
青い<br>

I wanted to try to see if any of those 3 would display right. What comes out is

??
青い
青い

Is there a way to tell the browser to change settings that would allow the text to actually display as 青い? Also, I specifically need the first line to display properly, and since it didn't even bother spitting out garbage, are there extra steps I would have to take?
www.bananamonkeyninja.com
The only webcomic endorsed by Banana Monkey Ninja

ニッキー
Posts: 90
Joined: Mon 07.28.2008 5:34 am
Native language: British English
Gender: Female
Location: Europe

Re: making Japanese text display in browser when coding php/html

Post by ニッキー » Sat 07.18.2009 4:04 pm

The last two lines look like you're using UTF-8, but not telling the browser what to expect. Do you have something in the <head> section of your HTML like this?

Code: Select all

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
As for the database result... it's been a long time since I last used PHP and you didn't say which database you're using, but I googled a bit and found some people using MySQL who had the same problem. They fixed it by doing the following after creating the connection to the database:

Code: Select all

mysql_query("SET NAMES 'utf8'");

User avatar
Dehitay
Posts: 1011
Joined: Fri 09.08.2006 8:36 pm
Native language: English
Gender: Male
Location: San Antonio, Texas, USA

Re: making Japanese text display in browser when coding php/html

Post by Dehitay » Sat 07.18.2009 6:22 pm

I guess I really should have posted the entire code since it was so ridiculously small anyways. But even without seeing the rest of it, you pretty much guessed just what it looks like. I was using MySQL and currently I only had title tags in the head. And the 2 code snippets you gave me solved the problem. Thanks a ton. Whenever I tried to google the problem, I got answers for problems completely unrelated to it.
www.bananamonkeyninja.com
The only webcomic endorsed by Banana Monkey Ninja

ニッキー
Posts: 90
Joined: Mon 07.28.2008 5:34 am
Native language: British English
Gender: Female
Location: Europe

Re: making Japanese text display in browser when coding php/html

Post by ニッキー » Sat 07.18.2009 8:58 pm

Glad I could help. :D

User avatar
keatonatron
Posts: 4838
Joined: Sat 02.04.2006 3:31 am
Native language: English
Gender: Male
Location: Tokyo (Via Seattle)
Contact:

Re: making Japanese text display in browser when coding php/html

Post by keatonatron » Sun 07.19.2009 12:41 am

Whenever doing any web stuff with Japanese, make sure you put UTF-8 tags in everything. It'll solve most of your problems :D

Post Reply