~hexmode/+junk/main

« back to all changes in this revision

Viewing changes to install-files/apps/phpmyadmin2.10.1/libraries/kanji-encoding.lib.php

  • Committer: Mark A. Hershberger
  • Date: 2008-01-05 19:38:56 UTC
  • Revision ID: hershberger@spawn-xp-20080105193856-6rnzgwa4nehue3qj
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/* $Id: kanji-encoding.lib.php 5208 2003-11-26 22:52:25Z rabus $ */
 
3
// vim: expandtab sw=4 ts=4 sts=4:
 
4
 
 
5
 
 
6
/**
 
7
 * Set of functions for kanji-encoding convert (available only with japanese
 
8
 * language)
 
9
 *
 
10
 * PHP4 configure requirements:
 
11
 *     --enable-mbstring --enable-mbstr-enc-trans --enable-mbregex
 
12
 *
 
13
 * 2002/2/22 - by Yukihiro Kawada <kawada@den.fujifilm.co.jp>
 
14
 */
 
15
 
 
16
/**
 
17
 * Gets the php internal encoding codes and sets the available encoding
 
18
 * codes list
 
19
 * 2002/1/4 by Y.Kawada
 
20
 *
 
21
 * @global  string   the current encoding code
 
22
 * @global  string   the available encoding codes list
 
23
 *
 
24
 * @return  boolean  always true
 
25
 */
 
26
function PMA_internal_enc_check() {
 
27
    global $internal_enc, $enc_list;
 
28
 
 
29
    $internal_enc = mb_internal_encoding();
 
30
    if ($internal_enc == 'EUC-JP') {
 
31
        $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
 
32
    } else {
 
33
        $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
 
34
    }
 
35
 
 
36
    return TRUE;
 
37
} // end of the 'PMA_internal_enc_check' function
 
38
 
 
39
 
 
40
/**
 
41
 * Reverses SJIS & EUC-JP position in the encoding codes list
 
42
 * 2002/1/4 by Y.Kawada
 
43
 *
 
44
 * @global  string   the available encoding codes list
 
45
 *
 
46
 * @return  boolean  always true
 
47
 */
 
48
function PMA_change_enc_order() {
 
49
    global $enc_list;
 
50
 
 
51
    $p            = explode(',', $enc_list);
 
52
    if ($p[1] == 'EUC-JP') {
 
53
        $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
 
54
    } else {
 
55
        $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
 
56
    }
 
57
 
 
58
    return TRUE;
 
59
} // end of the 'PMA_change_enc_order' function
 
60
 
 
61
 
 
62
/**
 
63
 * Kanji string encoding convert
 
64
 * 2002/1/4 by Y.Kawada
 
65
 *
 
66
 * @param   string   the string to convert
 
67
 * @param   string   the destinasion encoding code
 
68
 * @param   string   set 'kana' convert to JIS-X208-kana
 
69
 *
 
70
 * @global  string   the available encoding codes list
 
71
 *
 
72
 * @return  string   the converted string
 
73
 */
 
74
function PMA_kanji_str_conv($str, $enc, $kana) {
 
75
    global $enc_list;
 
76
 
 
77
    if ($enc == '' && $kana == '') {
 
78
        return $str;
 
79
    }
 
80
    $nw       = mb_detect_encoding($str, $enc_list);
 
81
 
 
82
    if ($kana == 'kana') {
 
83
        $dist = mb_convert_kana($str, 'KV', $nw);
 
84
        $str  = $dist;
 
85
    }
 
86
    if ($nw != $enc && $enc != '') {
 
87
        $dist = mb_convert_encoding($str, $enc, $nw);
 
88
    } else {
 
89
        $dist = $str;
 
90
    }
 
91
    return $dist;
 
92
} // end of the 'PMA_kanji_str_conv' function
 
93
 
 
94
 
 
95
/**
 
96
 * Kanji file encoding convert
 
97
 * 2002/1/4 by Y.Kawada
 
98
 *
 
99
 * @param   string   the name of the file to convert
 
100
 * @param   string   the destinasion encoding code
 
101
 * @param   string   set 'kana' convert to JIS-X208-kana
 
102
 *
 
103
 * @return  string   the name of the converted file
 
104
 */
 
105
function PMA_kanji_file_conv($file, $enc, $kana) {
 
106
    if ($enc == '' && $kana == '') {
 
107
        return $file;
 
108
    }
 
109
 
 
110
    $tmpfname = tempnam('', $enc);
 
111
    $fpd      = fopen($tmpfname, 'wb');
 
112
    $fps      = fopen($file, 'r');
 
113
    PMA_change_enc_order();
 
114
    while (!feof($fps)) {
 
115
        $line = fgets($fps, 4096);
 
116
        $dist = PMA_kanji_str_conv($line, $enc, $kana);
 
117
        fputs($fpd, $dist);
 
118
    } // end while
 
119
    PMA_change_enc_order();
 
120
    fclose($fps);
 
121
    fclose($fpd);
 
122
    unlink($file);
 
123
 
 
124
    return $tmpfname;
 
125
} // end of the 'PMA_kanji_file_conv' function
 
126
 
 
127
 
 
128
/**
 
129
 * Defines radio form fields to switch between encoding modes
 
130
 * 2002/1/4 by Y.Kawada
 
131
 *
 
132
 * @param   string   spaces character to prepend the output with
 
133
 *
 
134
 * @return  string   xhtml code for the radio controls
 
135
 */
 
136
function PMA_set_enc_form($spaces) {
 
137
    return "\n"
 
138
           . $spaces . '<input type="radio" name="knjenc" value="" checked="checked" />non' . "\n"
 
139
           . $spaces . '<input type="radio" name="knjenc" value="EUC-JP" />EUC' . "\n"
 
140
           . $spaces . '<input type="radio" name="knjenc" value="SJIS" />SJIS' . "\n"
 
141
           . $spaces . '&nbsp;' . $GLOBALS['strEncto'] . '<br />' . "\n"
 
142
           . $spaces . '<input type="checkbox" name="xkana" value="kana" />' . "\n"
 
143
           . $spaces . '&nbsp;' . $GLOBALS['strXkana'] . '<br />' . "\n";
 
144
} // end of the 'PMA_set_enc_form' function
 
145
 
 
146
 
 
147
PMA_internal_enc_check();
 
148
 
 
149
?>