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>
16 * Gets the php internal encoding codes and sets the available encoding
18 * 2002/1/4 by Y.Kawada
20 * @global string the current encoding code
21 * @global string the available encoding codes list
23 * @return boolean always true
25 function PMA_internal_enc_check() {
26 global $internal_enc, $enc_list;
28 $internal_enc = mb_internal_encoding();
29 if ($internal_enc == 'EUC-JP') {
30 $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
32 $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
36 } // end of the 'PMA_internal_enc_check' function
40 * Reverses SJIS & EUC-JP position in the encoding codes list
41 * 2002/1/4 by Y.Kawada
43 * @global string the available encoding codes list
45 * @return boolean always true
47 function PMA_change_enc_order() {
50 $p = explode(',', $enc_list);
51 if ($p[1] == 'EUC-JP') {
52 $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
54 $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
58 } // end of the 'PMA_change_enc_order' function
62 * Kanji string encoding convert
63 * 2002/1/4 by Y.Kawada
65 * @param string the string to convert
66 * @param string the destinasion encoding code
67 * @param string set 'kana' convert to JIS-X208-kana
69 * @global string the available encoding codes list
71 * @return string the converted string
73 function PMA_kanji_str_conv($str, $enc, $kana) {
76 if ($enc == '' && $kana == '') {
79 $nw = mb_detect_encoding($str, $enc_list);
81 if ($kana == 'kana') {
82 $dist = mb_convert_kana($str, 'KV', $nw);
85 if ($nw != $enc && $enc != '') {
86 $dist = mb_convert_encoding($str, $enc, $nw);
91 } // end of the 'PMA_kanji_str_conv' function
95 * Kanji file encoding convert
96 * 2002/1/4 by Y.Kawada
98 * @param string the name of the file to convert
99 * @param string the destinasion encoding code
100 * @param string set 'kana' convert to JIS-X208-kana
102 * @return string the name of the converted file
104 function PMA_kanji_file_conv($file, $enc, $kana) {
105 if ($enc == '' && $kana == '') {
109 $tmpfname = tempnam('', $enc);
110 $fpd = fopen($tmpfname, 'wb');
111 $fps = fopen($file, 'r');
112 PMA_change_enc_order();
113 while (!feof($fps)) {
114 $line = fgets($fps, 4096);
115 $dist = PMA_kanji_str_conv($line, $enc, $kana);
118 PMA_change_enc_order();
124 } // end of the 'PMA_kanji_file_conv' function
128 * Defines radio form fields to switch between encoding modes
129 * 2002/1/4 by Y.Kawada
131 * @param string spaces character to prepend the output with
133 * @return string xhtml code for the radio controls
135 function PMA_set_enc_form($spaces) {
137 . $spaces . '<input type="radio" name="knjenc" value="" checked="checked" />non' . "\n"
138 . $spaces . '<input type="radio" name="knjenc" value="EUC-JP" />EUC' . "\n"
139 . $spaces . '<input type="radio" name="knjenc" value="SJIS" />SJIS' . "\n"
140 . $spaces . ' ' . $GLOBALS['strEncto'] . '<br />' . "\n"
141 . $spaces . '<input type="checkbox" name="xkana" value="kana" />' . "\n"
142 . $spaces . ' ' . $GLOBALS['strXkana'] . '<br />' . "\n";
143 } // end of the 'PMA_set_enc_form' function
146 PMA_internal_enc_check();