Translation update done using Pootle.
[phpmyadmin/crack.git] / libraries / charset_conversion.lib.php
blob9acd1843a4d22de6ca4a9e52be9174c1c6fc800b
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Charset conversion functions.
6 * @package phpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
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);
17 // Finally detect which function we will use:
18 if ($cfg['RecodingEngine'] == 'iconv') {
19 if (@function_exists('iconv')) {
20 if ((@stristr(PHP_OS, 'AIX')) && (@strcasecmp(ICONV_IMPL, 'unknown') == 0) && (@strcasecmp(ICONV_VERSION, 'unknown') == 0)) {
21 $PMA_recoding_engine = PMA_CHARSET_ICONV_AIX;
22 } else {
23 $PMA_recoding_engine = PMA_CHARSET_ICONV;
25 } else {
26 $PMA_recoding_engine = PMA_CHARSET_NONE;
27 PMA_warnMissingExtension('iconv');
29 } elseif ($cfg['RecodingEngine'] == 'recode') {
30 if (@function_exists('recode_string')) {
31 $PMA_recoding_engine = PMA_CHARSET_RECODE;
32 } else {
33 $PMA_recoding_engine = PMA_CHARSET_NONE;
34 PMA_warnMissingExtension('recode');
36 } elseif ($cfg['RecodingEngine'] == 'auto') {
37 if (@function_exists('iconv')) {
38 if ((@stristr(PHP_OS, 'AIX')) && (@strcasecmp(ICONV_IMPL, 'unknown') == 0) && (@strcasecmp(ICONV_VERSION, 'unknown') == 0)) {
39 $PMA_recoding_engine = PMA_CHARSET_ICONV_AIX;
40 } else {
41 $PMA_recoding_engine = PMA_CHARSET_ICONV;
43 } elseif (@function_exists('recode_string')) {
44 $PMA_recoding_engine = PMA_CHARSET_RECODE;
45 } else {
46 $PMA_recoding_engine = PMA_CHARSET_NONE;
48 } else {
49 $PMA_recoding_engine = PMA_CHARSET_NONE;
52 /* Load AIX iconv wrapper if needed */
53 if ($PMA_recoding_engine == PMA_CHARSET_ICONV_AIX) {
54 require_once './libraries/iconv_wrapper.lib.php';
57 /**
58 * Converts encoding of text according to parameters with detected
59 * conversion function.
61 * @param string source charset
62 * @param string target charset
63 * @param string what to convert
65 * @return string converted text
67 * @access public
70 function PMA_convert_string($src_charset, $dest_charset, $what) {
71 if ($src_charset == $dest_charset) {
72 return $what;
74 switch ($GLOBALS['PMA_recoding_engine']) {
75 case PMA_CHARSET_RECODE:
76 return recode_string($src_charset . '..' . $dest_charset, $what);
77 case PMA_CHARSET_ICONV:
78 return iconv($src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $what);
79 case PMA_CHARSET_ICONV_AIX:
80 return PMA_aix_iconv_wrapper($src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $what);
81 default:
82 return $what;
84 } // end of the "PMA_convert_string()" function