Romanian update
[phpmyadmin/arisferyanto.git] / libraries / kanji-encoding.lib.php
blob2e5b9f83fa5a4e72e26f81ba855b8953edf8b55d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions for kanji-encoding convert (available only with japanese
5 * language)
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>
12 * @version $Id$
15 /**
16 * Gets the php internal encoding codes and sets the available encoding
17 * codes list
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';
31 } else {
32 $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
35 return TRUE;
36 } // end of the 'PMA_internal_enc_check' function
39 /**
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() {
48 global $enc_list;
50 $p = explode(',', $enc_list);
51 if ($p[1] == 'EUC-JP') {
52 $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
53 } else {
54 $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
57 return TRUE;
58 } // end of the 'PMA_change_enc_order' function
61 /**
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) {
74 global $enc_list;
76 if ($enc == '' && $kana == '') {
77 return $str;
79 $nw = mb_detect_encoding($str, $enc_list);
81 if ($kana == 'kana') {
82 $dist = mb_convert_kana($str, 'KV', $nw);
83 $str = $dist;
85 if ($nw != $enc && $enc != '') {
86 $dist = mb_convert_encoding($str, $enc, $nw);
87 } else {
88 $dist = $str;
90 return $dist;
91 } // end of the 'PMA_kanji_str_conv' function
94 /**
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 == '') {
106 return $file;
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);
116 fputs($fpd, $dist);
117 } // end while
118 PMA_change_enc_order();
119 fclose($fps);
120 fclose($fpd);
121 unlink($file);
123 return $tmpfname;
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) {
136 return "\n"
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 . '&nbsp;' . $GLOBALS['strEncto'] . '<br />' . "\n"
141 . $spaces . '<input type="checkbox" name="xkana" value="kana" />' . "\n"
142 . $spaces . '&nbsp;' . $GLOBALS['strXkana'] . '<br />' . "\n";
143 } // end of the 'PMA_set_enc_form' function
146 PMA_internal_enc_check();