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 available encoding codes list
25 * @return boolean always true
27 function PMA_Kanji_checkEncoding()
29 global $kanji_encoding_list;
31 $internal_enc = mb_internal_encoding();
32 if ($internal_enc == 'EUC-JP') {
33 $kanji_encoding_list = 'ASCII,EUC-JP,SJIS,JIS';
35 $kanji_encoding_list = 'ASCII,SJIS,EUC-JP,JIS';
39 } // end of the 'PMA_Kanji_checkEncoding' function
43 * Reverses SJIS & EUC-JP position in the encoding codes list
44 * 2002/1/4 by Y.Kawada
46 * @global string the available encoding codes list
48 * @return boolean always true
50 function PMA_Kanji_changeOrder()
52 global $kanji_encoding_list;
54 $parts = explode(',', $kanji_encoding_list);
55 if ($parts[1] == 'EUC-JP') {
56 $kanji_encoding_list = 'ASCII,SJIS,EUC-JP,JIS';
58 $kanji_encoding_list = 'ASCII,EUC-JP,SJIS,JIS';
62 } // end of the 'PMA_Kanji_changeOrder' function
66 * Kanji string encoding convert
67 * 2002/1/4 by Y.Kawada
69 * @param string $str the string to convert
70 * @param string $enc the destination encoding code
71 * @param string $kana set 'kana' convert to JIS-X208-kana
73 * @global string the available encoding codes list
75 * @return string the converted string
77 function PMA_Kanji_strConv($str, $enc, $kana)
79 global $kanji_encoding_list;
81 if ($enc == '' && $kana == '') {
84 $string_encoding = mb_detect_encoding($str, $kanji_encoding_list);
86 if ($kana == 'kana') {
87 $dist = mb_convert_kana($str, 'KV', $string_encoding);
90 if ($string_encoding != $enc && $enc != '') {
91 $dist = mb_convert_encoding($str, $enc, $string_encoding);
96 } // end of the 'PMA_Kanji_strConv' function
100 * Kanji file encoding convert
101 * 2002/1/4 by Y.Kawada
103 * @param string $file the name of the file to convert
104 * @param string $enc the destination encoding code
105 * @param string $kana set 'kana' convert to JIS-X208-kana
107 * @return string the name of the converted file
109 function PMA_Kanji_fileConv($file, $enc, $kana)
111 if ($enc == '' && $kana == '') {
115 $tmpfname = tempnam('', $enc);
116 $fpd = fopen($tmpfname, 'wb');
117 $fps = fopen($file, 'r');
118 PMA_Kanji_changeOrder();
119 while (!feof($fps)) {
120 $line = fgets($fps, 4096);
121 $dist = PMA_Kanji_strConv($line, $enc, $kana);
124 PMA_Kanji_changeOrder();
130 } // end of the 'PMA_Kanji_fileConv' function
134 * Defines radio form fields to switch between encoding modes
135 * 2002/1/4 by Y.Kawada
137 * @return string xhtml code for the radio controls
139 function PMA_Kanji_encodingForm()
142 . '<ul>' . "\n" . '<li>'
143 . '<input type="radio" name="knjenc" value="" checked="checked" '
145 . '<label for="kj-none">'
146 /* l10n: This is currently used only in Japanese locales */
147 . _pgettext('None encoding conversion', 'None')
149 . '<input type="radio" name="knjenc" value="EUC-JP" id="kj-euc" />'
150 . '<label for="kj-euc">EUC</label>' . "\n"
151 . '<input type="radio" name="knjenc" value="SJIS" id="kj-sjis" />'
152 . '<label for="kj-sjis">SJIS</label>' . "\n"
153 . '</li>' . "\n" . '<li>'
154 . '<input type="checkbox" name="xkana" value="kana" id="kj-kana" />'
156 . '<label for="kj-kana">'
157 /* l10n: This is currently used only in Japanese locales */
158 . __('Convert to Kana')
161 . '</li>' . "\n" . '</ul>'
163 } // end of the 'PMA_Kanji_encodingForm' function
166 PMA_Kanji_checkEncoding();