Read and display Japanese text from text file

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi there, a while ago, I posted a question regarding reading japanese
text from a text file.

Well, since I solved the problem, I thought I'd post my solution for
the benefit of other people with the same problem.

The plan was to make a script to read and display japanese text. I
will use it for making a japanese proverb script and for a japanese
language study script.

Method :

I wrote a simple kanji text file (saved with UTF-8 encoding)
I wrote a simple PHP script to display the file contents (saved with
I specified the content-type header for the HTML page :
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

*** All files have the same encoding. ***

UTF-8 supports japanese characters.

and it works!

this is my PHP (and HTML) script :

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP : Japanese Text File Read : Exercise 1</title>


//open file
$fp = fopen($filename,'r');

//loop through each line in the file
   //output current text file line
   print $line."<br>";
//close file handle



I know it's a very simple script, for testing purposes only. It
displays the contents of the japanese text file line by line.

The key was to save all files in the same encoding (I used UTF-8) and
to specify the encoding / charset in the HTML header (<meta
http-equiv="Content-Type" content="text/html; charset=utf-8">)

One could probably do the same thing in Shift_JIS encoding.

hope it helps anyone looking,


David Thomas.

Re: Read and display Japanese text from text file

Quoted text here. Click to load it

You should use the http header whenever able to...


  Daniel Tryba

Site Timeline