Page 1 of 2
Japanese Characters in php document
Posted: Sun Feb 05, 2006 4:57 am
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 "日本語のれんしゅう!"; ?>
What I end up with is " 日本語ã
Posted: Sun Feb 05, 2006 5:00 am
by onejoy1
Sorry! The output is actually " 日本語ã
Posted: Sun Feb 05, 2006 5:14 am
by Ree
You must indicate utf-8 as charset in your html file as well as have the actual file utf-8 encoded.
Posted: Sun Feb 05, 2006 12:57 pm
by onejoy1
And I'm still getting  ã
Posted: Sun Feb 05, 2006 2:07 pm
by gumphfy
I know it's a bit of a hazzle, but you could convert it to:
Code: Select all
日本語のれんしゅう
That's what I do on my site anyway...
Posted: Sun Feb 05, 2006 2:25 pm
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!
Posted: Sun Feb 05, 2006 4:15 pm
by onejoy1
The server I'm working in is php 4.3. Is it possible that Japanese support is in a newer version?
Posted: Sun Feb 05, 2006 4:44 pm
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.
Posted: Sun Feb 05, 2006 4:53 pm
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 "はじめ"; ?>
EDIT | Ignore the entities... phpBB messed up my copy & paste and I can't write Japanese off the top of my head

Posted: Sun Feb 05, 2006 4:54 pm
by Gambler
1) Make sure that you save files as UTF-8.
2) Try manually chosing encoding in the browser.
Posted: Sun Feb 05, 2006 5:07 pm
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
ã
Posted: Sun Feb 05, 2006 5:10 pm
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
ã
Posted: Sun Feb 05, 2006 5:11 pm
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
Posted: Sun Feb 05, 2006 5:29 pm
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.
Posted: Sun Feb 05, 2006 5:32 pm
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
