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>
15 if (! defined('PHPMYADMIN')) {
20 * Gets the php internal encoding codes and sets the available encoding
22 * 2002/1/4 by Y.Kawada
24 * @global string the current encoding code
25 * @global string the available encoding codes list
27 * @return boolean always true
29 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() {
54 $p = explode(',', $enc_list);
55 if ($p[1] == 'EUC-JP') {
56 $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
58 $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
62 } // end of the 'PMA_change_enc_order' function
66 * Kanji string encoding convert
67 * 2002/1/4 by Y.Kawada
69 * @param string the string to convert
70 * @param string the destinasion encoding code
71 * @param string 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_str_conv($str, $enc, $kana) {
80 if ($enc == '' && $kana == '') {
83 $nw = mb_detect_encoding($str, $enc_list);
85 if ($kana == 'kana') {
86 $dist = mb_convert_kana($str, 'KV', $nw);
89 if ($nw != $enc && $enc != '') {
90 $dist = mb_convert_encoding($str, $enc, $nw);
95 } // end of the 'PMA_kanji_str_conv' function
99 * Kanji file encoding convert
100 * 2002/1/4 by Y.Kawada
102 * @param string the name of the file to convert
103 * @param string the destinasion encoding code
104 * @param string set 'kana' convert to JIS-X208-kana
106 * @return string the name of the converted file
108 function PMA_kanji_file_conv($file, $enc, $kana) {
109 if ($enc == '' && $kana == '') {
113 $tmpfname = tempnam('', $enc);
114 $fpd = fopen($tmpfname, 'wb');
115 $fps = fopen($file, 'r');
116 PMA_change_enc_order();
117 while (!feof($fps)) {
118 $line = fgets($fps, 4096);
119 $dist = PMA_kanji_str_conv($line, $enc, $kana);
122 PMA_change_enc_order();
128 } // end of the 'PMA_kanji_file_conv' function
132 * Defines radio form fields to switch between encoding modes
133 * 2002/1/4 by Y.Kawada
135 * @param string spaces character to prepend the output with
137 * @return string xhtml code for the radio controls
139 function PMA_set_enc_form($spaces) {
141 . $spaces . '<input type="radio" name="knjenc" value="" checked="checked" />non' . "\n"
142 . $spaces . '<input type="radio" name="knjenc" value="EUC-JP" />EUC' . "\n"
143 . $spaces . '<input type="radio" name="knjenc" value="SJIS" />SJIS' . "\n"
144 . $spaces . ' ' . $GLOBALS['strEncto'] . '<br />' . "\n"
145 . $spaces . '<input type="checkbox" name="xkana" value="kana" />' . "\n"
146 . $spaces . ' ' . $GLOBALS['strXkana'] . '<br />' . "\n";
147 } // end of the 'PMA_set_enc_form' function
150 PMA_internal_enc_check();