2
/* $Id: kanji-encoding.lib.php 5208 2003-11-26 22:52:25Z rabus $ */
3
// vim: expandtab sw=4 ts=4 sts=4:
7
* Set of functions for kanji-encoding convert (available only with japanese
10
* PHP4 configure requirements:
11
* --enable-mbstring --enable-mbstr-enc-trans --enable-mbregex
13
* 2002/2/22 - by Yukihiro Kawada <kawada@den.fujifilm.co.jp>
17
* Gets the php internal encoding codes and sets the available encoding
19
* 2002/1/4 by Y.Kawada
21
* @global string the current encoding code
22
* @global string the available encoding codes list
24
* @return boolean always true
26
function PMA_internal_enc_check() {
27
global $internal_enc, $enc_list;
29
$internal_enc = mb_internal_encoding();
30
if ($internal_enc == 'EUC-JP') {
31
$enc_list = 'ASCII,EUC-JP,SJIS,JIS';
33
$enc_list = 'ASCII,SJIS,EUC-JP,JIS';
37
} // end of the 'PMA_internal_enc_check' function
41
* Reverses SJIS & EUC-JP position in the encoding codes list
42
* 2002/1/4 by Y.Kawada
44
* @global string the available encoding codes list
46
* @return boolean always true
48
function PMA_change_enc_order() {
51
$p = explode(',', $enc_list);
52
if ($p[1] == 'EUC-JP') {
53
$enc_list = 'ASCII,SJIS,EUC-JP,JIS';
55
$enc_list = 'ASCII,EUC-JP,SJIS,JIS';
59
} // end of the 'PMA_change_enc_order' function
63
* Kanji string encoding convert
64
* 2002/1/4 by Y.Kawada
66
* @param string the string to convert
67
* @param string the destinasion encoding code
68
* @param string set 'kana' convert to JIS-X208-kana
70
* @global string the available encoding codes list
72
* @return string the converted string
74
function PMA_kanji_str_conv($str, $enc, $kana) {
77
if ($enc == '' && $kana == '') {
80
$nw = mb_detect_encoding($str, $enc_list);
82
if ($kana == 'kana') {
83
$dist = mb_convert_kana($str, 'KV', $nw);
86
if ($nw != $enc && $enc != '') {
87
$dist = mb_convert_encoding($str, $enc, $nw);
92
} // end of the 'PMA_kanji_str_conv' function
96
* Kanji file encoding convert
97
* 2002/1/4 by Y.Kawada
99
* @param string the name of the file to convert
100
* @param string the destinasion encoding code
101
* @param string set 'kana' convert to JIS-X208-kana
103
* @return string the name of the converted file
105
function PMA_kanji_file_conv($file, $enc, $kana) {
106
if ($enc == '' && $kana == '') {
110
$tmpfname = tempnam('', $enc);
111
$fpd = fopen($tmpfname, 'wb');
112
$fps = fopen($file, 'r');
113
PMA_change_enc_order();
114
while (!feof($fps)) {
115
$line = fgets($fps, 4096);
116
$dist = PMA_kanji_str_conv($line, $enc, $kana);
119
PMA_change_enc_order();
125
} // end of the 'PMA_kanji_file_conv' function
129
* Defines radio form fields to switch between encoding modes
130
* 2002/1/4 by Y.Kawada
132
* @param string spaces character to prepend the output with
134
* @return string xhtml code for the radio controls
136
function PMA_set_enc_form($spaces) {
138
. $spaces . '<input type="radio" name="knjenc" value="" checked="checked" />non' . "\n"
139
. $spaces . '<input type="radio" name="knjenc" value="EUC-JP" />EUC' . "\n"
140
. $spaces . '<input type="radio" name="knjenc" value="SJIS" />SJIS' . "\n"
141
. $spaces . ' ' . $GLOBALS['strEncto'] . '<br />' . "\n"
142
. $spaces . '<input type="checkbox" name="xkana" value="kana" />' . "\n"
143
. $spaces . ' ' . $GLOBALS['strXkana'] . '<br />' . "\n";
144
} // end of the 'PMA_set_enc_form' function
147
PMA_internal_enc_check();