in reply to Re^2: MS Access Input -> Japanese Output
in thread MS Access Input -> Japanese Output
Presuming the data you get from mysql actually is in UTF-8, you could try two alternatives:
(1) - The straightforward approach: add a line binmode STDOUT, ":utf8"; (e.g. before the line print header(-charset=>'utf-8');
This might already suffice, as it's supposed to make sure that the CGI output is being written as UTF-8 (theoretically, there could still be a few other pitfalls, though...)
(2) - The safe approach: add a little conversion function
use Encode "encode"; sub U2Entity { return '&#x'.unpack("H*", encode("ucs2be", shift)).';'; }
and then modify the lines where you output the non-english table cells to read: print "<td>" . U2Entity( $resptr->{"Kana"} ); , etc.
In this case you no longer need to declare -charset=>'utf-8', as now everything is output in plain ASCII -- for example the Hiragana 'a' would be converted to its HTML entity representation あ
If both of these approaches do not work (which might well be the case), then the data from mysql most likely isn't in UTF-8. To figure out what you're actually being passed from the mysql side, try the following:
Add another little function
sub Any2Hex { return unpack("H*", shift); }
and then use that one instead of U2Entity(), i.e. print "<td>" . Any2Hex( $resptr->{"Kana"} );
and report back which hex values you're getting... :)
(In case you're merely seeing 3f (the hex value of the ASCII code representing the question mark character), then the problem is most likely the mysql setup... --> How did you create your mysql tables, etc...?)
Cheers,
Almut
BTW, just as an aside: to create a proper, complete HTML file, you'll probably also want to output the <html> and <body> tags...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: MS Access Input -> Japanese Output
by Zettai (Acolyte) on Nov 23, 2006 at 17:23 UTC | |
by almut (Canon) on Nov 23, 2006 at 17:56 UTC | |
by Zettai (Acolyte) on Nov 23, 2006 at 18:51 UTC | |
by almut (Canon) on Nov 23, 2006 at 19:51 UTC | |
by Zettai (Acolyte) on Nov 26, 2006 at 17:08 UTC |