2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions for kanji-encoding convert (available only with japanese
7 * PHP4 configure requirements:
8 * --enable-mbstring --enable-mbstr-enc-trans --enable-mbregex
10 * 2002/2/22 - by Yukihiro Kawada <kawada@den.fujifilm.co.jp>
14 if (! defined('PHPMYADMIN')) {
19 * Gets the php internal encoding codes and sets the available encoding
21 * 2002/1/4 by Y.Kawada
23 * @global string the current encoding code
24 * @global string the available encoding codes list
26 * @return boolean always true
28 function PMA_internal_enc_check()
30 global $internal_enc, $enc_list;
32 $internal_enc = mb_internal_encoding();
33 if ($internal_enc == 'EUC-JP') {
34 $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
36 $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
40 } // end of the 'PMA_internal_enc_check' function
44 * Reverses SJIS & EUC-JP position in the encoding codes list
45 * 2002/1/4 by Y.Kawada
47 * @global string the available encoding codes list
49 * @return boolean always true
51 function PMA_change_enc_order()
55 $p = explode(',', $enc_list);
56 if ($p[1] == 'EUC-JP') {
57 $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
59 $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
63 } // end of the 'PMA_change_enc_order' function
67 * Kanji string encoding convert
68 * 2002/1/4 by Y.Kawada
70 * @param string the string to convert
71 * @param string the destination encoding code
72 * @param string set 'kana' convert to JIS-X208-kana
74 * @global string the available encoding codes list
76 * @return string the converted string
78 function PMA_kanji_str_conv($str, $enc, $kana)
82 if ($enc == '' && $kana == '') {
85 $nw = mb_detect_encoding($str, $enc_list);
87 if ($kana == 'kana') {
88 $dist = mb_convert_kana($str, 'KV', $nw);
91 if ($nw != $enc && $enc != '') {
92 $dist = mb_convert_encoding($str, $enc, $nw);
97 } // end of the 'PMA_kanji_str_conv' function
101 * Kanji file encoding convert
102 * 2002/1/4 by Y.Kawada
104 * @param string the name of the file to convert
105 * @param string the destination encoding code
106 * @param string set 'kana' convert to JIS-X208-kana
108 * @return string the name of the converted file
110 function PMA_kanji_file_conv($file, $enc, $kana)
112 if ($enc == '' && $kana == '') {
116 $tmpfname = tempnam('', $enc);
117 $fpd = fopen($tmpfname, 'wb');
118 $fps = fopen($file, 'r');
119 PMA_change_enc_order();
120 while (!feof($fps)) {
121 $line = fgets($fps, 4096);
122 $dist = PMA_kanji_str_conv($line, $enc, $kana);
125 PMA_change_enc_order();
131 } // end of the 'PMA_kanji_file_conv' function
135 * Defines radio form fields to switch between encoding modes
136 * 2002/1/4 by Y.Kawada
138 * @param string spaces character to prepend the output with
140 * @return string xhtml code for the radio controls
142 function PMA_set_enc_form($spaces)
145 /* l10n: This is currently used only in Japanese locales */
146 . $spaces . '<ul>' . "\n" . '<li>'
147 . $spaces . '<input type="radio" name="knjenc" value="" checked="checked" id="kj-none" /><label for="kj-none">' . _pgettext('None encoding conversion', 'None') . "</label>\n"
148 . $spaces . '<input type="radio" name="knjenc" value="EUC-JP" id="kj-euc" /><label for="kj-euc">EUC</label>' . "\n"
149 . $spaces . '<input type="radio" name="knjenc" value="SJIS" id="kj-sjis" /><label for="kj-sjis">SJIS</label>' . "\n"
150 . $spaces . '</li>' . "\n" . '<li>'
151 . $spaces . '<input type="checkbox" name="xkana" value="kana" id="kj-kana" />' . "\n"
152 /* l10n: This is currently used only in Japanese locales */
153 . $spaces . '<label for="kj-kana">' . __('Convert to Kana') . '</label><br />' . "\n"
154 . $spaces . '</li>' . "\n" . '</ul>'
156 } // end of the 'PMA_set_enc_form' function
159 PMA_internal_enc_check();