Çözüm çok karmaşık.
There are 3 parts of the solution:
Part 1: Install FPDF Chinese Plug-in
Part 2: Convert NCR format to UTF-8
Part 3: Convert UTF-8 format to BIG5 (or any target encoding)
Part 1
I fetched the FPDF Chinese Plug-in from here: http://dev.xoofoo.org/modules/content/d1/d6e/a00073.html
It is used to display Chinese characters in FPDF, and fetches all the Chinese fonts needed. To install this plug-in, just include it in PHP. (but for my case, I use another plug-in named CellPDF, which crashes with this Chinese Plug-in; thus, I have to merge the codes and resolve the conflicts)
Part 2
UTF-8 için NCR biçimini dönüştürmek için, ben aşağıdaki kodları kullanın:
function html_entity_decode_utf8($string)
{
static $trans_tbl;
// replace numeric entities
$string = preg_replace('~&#x([0-9a-f]+);~ei', 'code2utf(hexdec("\\1"))', $string);
$string = preg_replace('~&#([0-9]+);~e', 'code2utf(\\1)', $string);
// replace literal entities
if (!isset($trans_tbl))
{
$trans_tbl = array();
foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key)
$trans_tbl[$key] = utf8_encode($val);
}
return strtr($string, $trans_tbl);
}
function code2utf($num)
{
if ($num < 128) return chr($num);
if ($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
if ($num < 65536) return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
if ($num < 2097152) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
return '';
}
which is written by laurynas butkus at php.net (link: http://www.php.net/manual/en/function.html-entity-decode.php)
Though this piece of code itself converts NCR format to "monster characters", I know it is a good start.
Part 3
After I digged deep in php.net, I found a nice function: iconv, to convert encoding.
So I wrap the above codes with the following function:
function ncr_decode($string, $target_encoding='BIG5') {
return iconv('UTF-8', 'BIG5', html_entity_decode_utf8($string));
}
Ben NCR dizeleri önceki satırı dönüştürmek istiyorsanız, bu nedenle, ben sadece bu fonksiyonu çalıştırmak için gereken:
ncr_decode("這個一個例子");
P.S. Varsayılan olarak, ben BIG5 hedef kodlama ayarlayabilirsiniz.
İşte bu!