Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / iconv_wrapper.lib.php
blob9bacffa82eb699a630f89e39376426ae88e6def3
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)
59 global $gnu_iconv_to_aix_iconv_codepage_map;
61 // Check for transliteration argument at the end of output character set name
62 $translit_search = strpos(strtolower($out_charset), '//translit');
63 $using_translit = (!($translit_search === false));
65 // Extract "plain" output character set name
66 // (without any transliteration argument)
67 $out_charset_plain = ($using_translit
68 ? substr($out_charset, 0, $translit_search)
69 : $out_charset);
71 // Transform name of input character set (if found)
72 $in_charset_exisits = array_key_exists(
73 strtolower($in_charset),
74 $gnu_iconv_to_aix_iconv_codepage_map
76 if ($in_charset_exisits) {
77 $in_charset = $gnu_iconv_to_aix_iconv_codepage_map[strtolower($in_charset)];
80 // Transform name of "plain" output character set (if found)
81 $out_charset_plain_exists = array_key_exists(
82 strtolower($out_charset_plain),
83 $gnu_iconv_to_aix_iconv_codepage_map
85 if ($out_charset_plain_exists) {
86 $out_charset_plain = $gnu_iconv_to_aix_iconv_codepage_map[
87 strtolower($out_charset_plain)];
90 // Add transliteration argument again (exactly as specified by user) if used
91 // Build the output character set name that we will use
92 $out_charset = ($using_translit
93 ? $out_charset_plain . substr($out_charset, $translit_search)
94 : $out_charset_plain);
96 // NOTE: Transliteration not supported; we will use the "plain"
97 // output character set name
98 $out_charset = $out_charset_plain;
100 // Call iconv() with the possibly modified parameters
101 $result = iconv($in_charset, $out_charset, $str);
102 return $result;
103 } // end of the "PMA_aix_iconv_wrapper()" function