2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Charset conversion functions.
8 if (! defined('PHPMYADMIN')) {
12 define('PMA_CHARSET_NONE', 0);
13 define('PMA_CHARSET_ICONV', 1);
14 define('PMA_CHARSET_RECODE', 2);
15 define('PMA_CHARSET_ICONV_AIX', 3);
16 define('PMA_CHARSET_MB', 4);
18 if (! isset($GLOBALS['cfg']['RecodingEngine'])) {
19 $GLOBALS['cfg']['RecodingEngine'] = '';
21 // Finally detect which function we will use:
22 if ($GLOBALS['cfg']['RecodingEngine'] == 'iconv') {
23 if (@function_exists
('iconv')) {
24 if ((@stristr
(PHP_OS
, 'AIX'))
25 && (@strcasecmp
(ICONV_IMPL
, 'unknown') == 0)
26 && (@strcasecmp
(ICONV_VERSION
, 'unknown') == 0)
28 $PMA_recoding_engine = PMA_CHARSET_ICONV_AIX
;
30 $PMA_recoding_engine = PMA_CHARSET_ICONV
;
33 $PMA_recoding_engine = PMA_CHARSET_NONE
;
34 PMA_warnMissingExtension('iconv');
36 } elseif ($GLOBALS['cfg']['RecodingEngine'] == 'recode') {
37 if (@function_exists
('recode_string')) {
38 $PMA_recoding_engine = PMA_CHARSET_RECODE
;
40 $PMA_recoding_engine = PMA_CHARSET_NONE
;
41 PMA_warnMissingExtension('recode');
43 } elseif ($GLOBALS['cfg']['RecodingEngine'] == 'mb') {
44 if (@function_exists
('mb_convert_encoding')) {
45 $PMA_recoding_engine = PMA_CHARSET_MB
;
47 $PMA_recoding_engine = PMA_CHARSET_NONE
;
48 PMA_warnMissingExtension('mbstring');
50 } elseif ($GLOBALS['cfg']['RecodingEngine'] == 'auto') {
51 if (@function_exists
('iconv')) {
52 if ((@stristr
(PHP_OS
, 'AIX'))
53 && (@strcasecmp
(ICONV_IMPL
, 'unknown') == 0)
54 && (@strcasecmp
(ICONV_VERSION
, 'unknown') == 0)
56 $PMA_recoding_engine = PMA_CHARSET_ICONV_AIX
;
58 $PMA_recoding_engine = PMA_CHARSET_ICONV
;
60 } elseif (@function_exists
('recode_string')) {
61 $PMA_recoding_engine = PMA_CHARSET_RECODE
;
62 } elseif (@function_exists
('mb_convert_encoding')) {
63 $PMA_recoding_engine = PMA_CHARSET_MB
;
65 $PMA_recoding_engine = PMA_CHARSET_NONE
;
68 $PMA_recoding_engine = PMA_CHARSET_NONE
;
71 /* Load AIX iconv wrapper if needed */
72 if ($PMA_recoding_engine == PMA_CHARSET_ICONV_AIX
) {
73 include_once './libraries/iconv_wrapper.lib.php';
77 * Converts encoding of text according to parameters with detected
78 * conversion function.
80 * @param string $src_charset source charset
81 * @param string $dest_charset target charset
82 * @param string $what what to convert
84 * @return string converted text
89 function PMA_convertString($src_charset, $dest_charset, $what)
91 if ($src_charset == $dest_charset) {
94 switch ($GLOBALS['PMA_recoding_engine']) {
95 case PMA_CHARSET_RECODE
:
96 return recode_string($src_charset . '..' . $dest_charset, $what);
97 case PMA_CHARSET_ICONV
:
99 $src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $what
101 case PMA_CHARSET_ICONV_AIX
:
102 return PMA_convertAIXIconv(
103 $src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $what
106 return mb_convert_encoding(
107 $what, $dest_charset, $src_charset
112 } // end of the "PMA_convertString()" function