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 $PMA_recoding_engine = PMA_getIconvRecodingEngine();
26 $PMA_recoding_engine = PMA_CHARSET_NONE
;
27 PMA_warnMissingExtension('iconv');
29 } elseif ($GLOBALS['cfg']['RecodingEngine'] == 'recode') {
30 if (@function_exists
('recode_string')) {
31 $PMA_recoding_engine = PMA_CHARSET_RECODE
;
33 $PMA_recoding_engine = PMA_CHARSET_NONE
;
34 PMA_warnMissingExtension('recode');
36 } elseif ($GLOBALS['cfg']['RecodingEngine'] == 'mb') {
37 if (@function_exists
('mb_convert_encoding')) {
38 $PMA_recoding_engine = PMA_CHARSET_MB
;
40 $PMA_recoding_engine = PMA_CHARSET_NONE
;
41 PMA_warnMissingExtension('mbstring');
43 } elseif ($GLOBALS['cfg']['RecodingEngine'] == 'auto') {
45 * We also need to verify iconv works, see
46 * https://github.com/phpmyadmin/phpmyadmin/issues/11787/
48 * https://bugs.php.net/bug.php?id=44096
50 if (@function_exists
('iconv') && @iconv_strlen
('', 'cp1250') !== false) {
51 $PMA_recoding_engine = PMA_getIconvRecodingEngine();
52 } elseif (@function_exists
('recode_string')) {
53 $PMA_recoding_engine = PMA_CHARSET_RECODE
;
54 } elseif (@function_exists
('mb_convert_encoding')) {
55 $PMA_recoding_engine = PMA_CHARSET_MB
;
57 $PMA_recoding_engine = PMA_CHARSET_NONE
;
60 $PMA_recoding_engine = PMA_CHARSET_NONE
;
63 /* Load AIX iconv wrapper if needed */
64 if ($PMA_recoding_engine == PMA_CHARSET_ICONV_AIX
) {
65 include_once './libraries/iconv_wrapper.lib.php';
69 * Determines the correct recoding engine to use
71 * @return int $PMA_recoding_engine
76 function PMA_getIconvRecodingEngine()
78 if ((@stristr
(PHP_OS
, 'AIX'))
79 && (@strcasecmp
(ICONV_IMPL
, 'unknown') == 0)
80 && (@strcasecmp
(ICONV_VERSION
, 'unknown') == 0)
82 return PMA_CHARSET_ICONV_AIX
;
84 return PMA_CHARSET_ICONV
;
89 * Converts encoding of text according to parameters with detected
90 * conversion function.
92 * @param string $src_charset source charset
93 * @param string $dest_charset target charset
94 * @param string $what what to convert
96 * @return string converted text
101 function PMA_convertString($src_charset, $dest_charset, $what)
103 if ($src_charset == $dest_charset) {
106 switch ($GLOBALS['PMA_recoding_engine']) {
107 case PMA_CHARSET_RECODE
:
108 return recode_string($src_charset . '..' . $dest_charset, $what);
109 case PMA_CHARSET_ICONV
:
111 $src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $what
113 case PMA_CHARSET_ICONV_AIX
:
114 return PMA_convertAIXIconv(
115 $src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $what
118 return mb_convert_encoding(
119 $what, $dest_charset, $src_charset
124 } // end of the "PMA_convertString()" function