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
UTF-8
encoding)
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 :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP : Japanese Text File Read : Exercise 1</title>
</head>
<body>
<?php
$filename="japanese.txt";
//open file
$fp = fopen($filename,'r');
//loop through each line in the file
while($line=fgets($fp))
{
//output current text file line
print $line."<br>";
}
//close file handle
fclose($fp);
?>
</body>
</html>
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,
regards,
David Thomas.