Merge pull request #431 from xmujay/0609_monitor
[phpmyadmin/aamir.git] / libraries / iconv_wrapper.lib.php
blobeddb19353f83cb8f73eb8b63e2394bee53b6038d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
7 if (! defined('PHPMYADMIN')) {
8 exit;
11 /**
12 * GNU iconv code set to IBM AIX libiconv code set table
13 * Keys of this table should be in lowercase,
14 * and searches should be performed using lowercase!
16 $gnu_iconv_to_aix_iconv_codepage_map = array (
17 // "iso-8859-[1-9]" --> "ISO8859-[1-9]" according to
18 // http://publibn.boulder.ibm.com/doc_link/en_US/
19 // a_doc_lib/libs/basetrf2/setlocale.htm
20 'iso-8859-1' => 'ISO8859-1',
21 'iso-8859-2' => 'ISO8859-2',
22 'iso-8859-3' => 'ISO8859-3',
23 'iso-8859-4' => 'ISO8859-4',
24 'iso-8859-5' => 'ISO8859-5',
25 'iso-8859-6' => 'ISO8859-6',
26 'iso-8859-7' => 'ISO8859-7',
27 'iso-8859-8' => 'ISO8859-8',
28 'iso-8859-9' => 'ISO8859-9',
30 // "big5" --> "IBM-eucTW" according to
31 // http://kadesh.cepba.upc.es/mancpp/classref/ref/ITranscoder_DSC.htm
32 'big5' => 'IBM-eucTW',
34 // Other mappings corresponding to the phpMyAdmin dropdown box when using the
35 // charset conversion feature
36 'euc-jp' => 'IBM-eucJP',
37 'koi8-r' => 'IBM-eucKR',
38 'ks_c_5601-1987' => 'KSC5601.1987-0',
39 'tis-620' => 'TIS-620',
40 'utf-8' => 'UTF-8'
43 /**
44 * Wrapper around IBM AIX iconv(), whose character set naming differs
45 * from the GNU version of iconv().
47 * @param string $in_charset input character set
48 * @param string $out_charset output character set
49 * @param string $str the string to convert
51 * @return mixed converted string or false on failure
53 * @access public
56 function PMA_aix_iconv_wrapper($in_charset, $out_charset, $str)
58 list($in_charset, $out_charset) = PMA_aix_iconv_mapCharsets(
59 $in_charset, $out_charset
61 // Call iconv() with the possibly modified parameters
62 return iconv($in_charset, $out_charset, $str);
63 } // end of the "PMA_aix_iconv_wrapper()" function
65 /**
66 * Maps input and output character set names to corresponding AIX ones
68 * @param string $in_charset input character set
69 * @param string $out_charset output character set
71 * @return array array of mapped input and output character set names
73 function PMA_aix_iconv_mapCharsets($in_charset, $out_charset)
75 global $gnu_iconv_to_aix_iconv_codepage_map;
77 // Check for transliteration argument at the end of output character set name
78 $translit_search = strpos(strtolower($out_charset), '//translit');
79 $using_translit = (!($translit_search === false));
81 // Extract "plain" output character set name
82 // (without any transliteration argument)
83 $out_charset_plain = ($using_translit
84 ? substr($out_charset, 0, $translit_search)
85 : $out_charset);
87 // Transform name of input character set (if found)
88 $in_charset_exisits = array_key_exists(
89 strtolower($in_charset),
90 $gnu_iconv_to_aix_iconv_codepage_map
92 if ($in_charset_exisits) {
93 $in_charset = $gnu_iconv_to_aix_iconv_codepage_map[strtolower($in_charset)];
96 // Transform name of "plain" output character set (if found)
97 $out_charset_plain_exists = array_key_exists(
98 strtolower($out_charset_plain),
99 $gnu_iconv_to_aix_iconv_codepage_map
101 if ($out_charset_plain_exists) {
102 $out_charset_plain = $gnu_iconv_to_aix_iconv_codepage_map[
103 strtolower($out_charset_plain)];
106 // Add transliteration argument again (exactly as specified by user) if used
107 // Build the output character set name that we will use
108 $out_charset = ($using_translit
109 ? $out_charset_plain . substr($out_charset, $translit_search)
110 : $out_charset_plain);
112 // NOTE: Transliteration not supported; we will use the "plain"
113 // output character set name
114 $out_charset = $out_charset_plain;
116 return array($in_charset, $out_charset);