Japanese Characters in php document

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

onejoy1
Forum Newbie
Posts: 14
Joined: Sun Feb 05, 2006 4:50 am

Japanese Characters in php document

Post by onejoy1 »

I can't get Japanese characters to show up in a php document. I'm using unicode encoding, and my computer supports japanese characters. But when I have this:

Code: Select all

<? echo "&#26085;&#26412;&#35486;&#12398;&#12428;&#12435;&#12375;&#12421;&#12358;&#65281;"; ?>
What I end up with is " 日本語ã
onejoy1
Forum Newbie
Posts: 14
Joined: Sun Feb 05, 2006 4:50 am

Post by onejoy1 »

Sorry! The output is actually " 日本語ã
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

You must indicate utf-8 as charset in your html file as well as have the actual file utf-8 encoded.
onejoy1
Forum Newbie
Posts: 14
Joined: Sun Feb 05, 2006 4:50 am

Post by onejoy1 »

And I'm still getting  ã
gumphfy
Forum Newbie
Posts: 23
Joined: Fri Jan 06, 2006 10:18 am

Post by gumphfy »

I know it's a bit of a hazzle, but you could convert it to:

Code: Select all

&#26085;&#26412;&#35486;&#12398;&#12428;&#12435;&#12375;&#12421;&#12358;
That's what I do on my site anyway...
onejoy1
Forum Newbie
Posts: 14
Joined: Sun Feb 05, 2006 4:50 am

Post by onejoy1 »

I'm going to be making an entire website for my school's japanese department with quizzes and cheat-sheets for their students to use as study guides. So while that might work for just that, I can't do that for the whole website.

Please help!
onejoy1
Forum Newbie
Posts: 14
Joined: Sun Feb 05, 2006 4:50 am

Post by onejoy1 »

The server I'm working in is php 4.3. Is it possible that Japanese support is in a newer version?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Check that your server is actually sending a UTF-8 charset in the header, I think the header overrides anything in the meta-tag but I might be wrong.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

<?php header("Content-type: text/css; charset: UTF-8"); ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body>
<? echo "&#12399;&#12376;&#12417;"; ?>
EDIT | Ignore the entities... phpBB messed up my copy & paste and I can't write Japanese off the top of my head :(
Gambler
Forum Contributor
Posts: 246
Joined: Thu Dec 08, 2005 7:10 pm

Post by Gambler »

1) Make sure that you save files as UTF-8.
2) Try manually chosing encoding in the browser.
onejoy1
Forum Newbie
Posts: 14
Joined: Sun Feb 05, 2006 4:50 am

Post by onejoy1 »

1) Make sure that you save files as UTF-8.
2) Try manually chosing encoding in the browser.
I don't understand what Gambler means by save files as utf-8, unless you mean to make sure that when I save them, the encoding is set to utf-8?

And interestingly enough, when I added

Code: Select all

<?php header("Content-type: text/css; charset: UTF-8"); ?>
I got:

Warning: Cannot modify header information - headers already sent by (output started at /home/users/sjg5005/http/nihongo/directory2.php:1) in /home/users/sjg5005/http/nihongo/directory2.php on line 1
ã
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

onejoy1 wrote:
1) Make sure that you save files as UTF-8.
2) Try manually chosing encoding in the browser.
I don't understand what Gambler means by save files as utf-8, unless you mean to make sure that when I save them, the encoding is set to utf-8?

And interestingly enough, when I added

Code: Select all

<?php header("Content-type: text/css; charset: UTF-8"); ?>
I got:

Warning: Cannot modify header information - headers already sent by (output started at /home/users/sjg5005/http/nihongo/directory2.php:1) in /home/users/sjg5005/http/nihongo/directory2.php on line 1
ã
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

mbstring is not needed to output utf-8, it is needed to fix certain things like multi-byte strings counting as longer then they actually are with strlen() for example. As for the header issue that is really a simple problem, you already have output before you made the call to header(). Fix that and let us know what happens
onejoy1
Forum Newbie
Posts: 14
Joined: Sun Feb 05, 2006 4:50 am

Post by onejoy1 »

I have no idea what the output before the header call is.

Code: Select all

<?php header("Content-type: text/css; charset: UTF-8"); ?>
is line 1 of the file.

I'm unfortunately using dreamweaver to do this, but I also tried it in notepad and wordpad, and had the same error. So I don't think dreamweaver is putting anything at the top.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

onejoy1 wrote:I have no idea what the output before the header call is.

Code: Select all

<?php header("Content-type: text/css; charset: UTF-8"); ?>
is line 1 of the file.

I'm unfortunately using dreamweaver to do this, but I also tried it in notepad and wordpad, and had the same error. So I don't think dreamweaver is putting anything at the top.
Is this file being included into another file that's already sent output or has a blank line or a tab at the start?

NOTE: Dreamweaver has a habit of spitting invisiable characters into the start of files which causes such header errors... copying & pasting into wordpad would most likely copy such characters too.... re-typing would not ;)
Post Reply