Jump to content

Problem with Japanese characters


sjb500

Recommended Posts

Hi

 

I'm fairly new to php coding and I've recently inherited a php site with a backend mysql database. Some of the legacy client data represents Japanese characters and on a simple php page I am trying to get these characters to display properly. I've stripped down the problem page and produced a simple test . However the best I've been able to do is get a couple of characters to show while the remainder remain as square blocks.

 

My code is

 

<?php
header('Content-Type: text/html;charset=utf-8');
echo "<html><head><style type='text/css'>th,td {border:solid 1px silver}</style></head><body style=\"font-family: Arial Unicode MS\"><h1>Report</h1>";
echo 'アクセスは撥ねりません。'; 

function hex2str($hex) 
{ 
$r = ''; 
for ($i = 0; $i<strlen($hex)-1;$i+=2)$r .= chr(hexdec($hex[$i] . $hex[$i + 1])); 
return $r; 
}

function unicode_decode($str) 
{
return preg_replace("/\%u([0-9A-F]{4})/ie","iconv('utf-16', 'utf-8', hex2str(\"$1\"))", $str); 
} 


echo "<font size='24px'>";
echo  unicode_decode("%u85E4%u7530%u5316%u6210%u682A%u5F0F%u4F1A%u793E");
echo "</font>";
echo "</body></html";

 

The first (japanese)echo statement works fine but the second one, where I run it through a decoder, has the problem . Has anyone had any experience of this problem? Thanks

Link to comment
https://forums.phpfreaks.com/topic/196878-problem-with-japanese-characters/
Share on other sites

Can you imagine Japanese people coding in this way? I cant!! There must be a simpler way and I think you maybe trying something too complicated. Perhaps return to basics and just try displaying the characters in the browser as they come out of the database and see what happens. As long as you have utf-8 character encoding you should be OK as far as I know.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.