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>
15 if (!defined('PMA_ENCODING_LIB_INCLUDED')) {
16 define('PMA_ENCODING_LIB_INCLUDED', 1);
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() {
29 global $internal_enc, $enc_list;
31 $internal_enc = mb_internal_encoding();
32 if ($internal_enc == 'EUC-JP') {
33 $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
35 $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
39 } // end of the 'PMA_internal_enc_check' 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_change_enc_order() {
53 $p = split(',', $enc_list);
54 if ($p[1] == 'EUC-JP') {
55 $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
57 $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
61 } // end of the 'PMA_change_enc_order' function
65 * Kanji string encoding convert
66 * 2002/1/4 by Y.Kawada
68 * @param string the string to convert
69 * @param string the destinasion encoding code
70 * @param string set 'kana' convert to JIS-X208-kana
72 * @global string the available encoding codes list
74 * @return string the converted string
76 function PMA_kanji_str_conv($str, $enc, $kana) {
79 if ($enc == '' && $kana == '') {
82 $nw = mb_detect_encoding($str, $enc_list);
84 if ($kana == 'kana') {
85 $dist = mb_convert_kana($str, 'KV', $nw);
88 if ($nw != $enc && $enc != '') {
89 $dist = mb_convert_encoding($str, $enc, $nw);
94 } // end of the 'PMA_kanji_str_conv' function
98 * Kanji file encoding convert
99 * 2002/1/4 by Y.Kawada
101 * @param string the name of the file to convert
102 * @param string the destinasion encoding code
103 * @param string set 'kana' convert to JIS-X208-kana
105 * @return string the name of the converted file
107 function PMA_kanji_file_conv($file, $enc, $kana) {
108 if ($enc == '' && $kana == '') {
112 $tmpfname = tempnam('', $enc);
113 $fpd = fopen($tmpfname, 'wb');
114 $fps = fopen($file, 'r');
115 PMA_change_enc_order();
116 while (!feof($fps)) {
117 $line = fgets($fps, 4096);
118 $dist = PMA_kanji_str_conv($line, $enc, $kana);
121 PMA_change_enc_order();
127 } // end of the 'PMA_kanji_file_conv' function
131 * Defines radio form fields to switch between encoding modes
132 * 2002/1/4 by Y.Kawada
134 * @param string spaces character to prepend the output with
136 * @return string xhtml code for the radio controls
138 function PMA_set_enc_form($spaces) {
140 . $spaces . '<input type="radio" name="knjenc" value="" checked="checked" />non' . "\n"
141 . $spaces . '<input type="radio" name="knjenc" value="EUC-JP" />EUC' . "\n"
142 . $spaces . '<input type="radio" name="knjenc" value="SJIS" />SJIS' . "\n"
143 . $spaces . ' ' . $GLOBALS['strEncto'] . '<br />' . "\n"
144 . $spaces . '<input type="checkbox" name="xkana" value="kana" />' . "\n"
145 . $spaces . ' ' . $GLOBALS['strXkana'] . '<br />' . "\n";
146 } // end of the 'PMA_set_enc_form' function
149 PMA_internal_enc_check();
151 } // $__PMA_ENCODING_LIB_INCLUDED