【php开源代码栏目提醒】:网学会员在php开源代码频道为大家收集整理了charset_conversion.lib.php提供大家参考,希望对大家有所帮助!
<?php
/* $Id: charset_conversion.lib.php,v 2.9 2006/01/17 17:02:30 cybot_tm Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Charset conversion functions.
*/
/**
* Loads the recode or iconv extensions if any of it is not loaded yet
*/
if (isset($cfg['AllowAnywhereRecoding'])
&& $cfg['AllowAnywhereRecoding']
&& $allow_recoding) {
if ($cfg['RecodingEngine'] == 'recode') {
if (!@extension_loaded('recode')) {
PMA_dl('recode');
if (!@extension_loaded('recode')) {
echo $strCantLoadRecodeIconv;
exit;
}
}
$PMA_recoding_engine = 'recode';
} elseif ($cfg['RecodingEngine'] == 'iconv') {
if (!@extension_loaded('iconv')) {
PMA_dl('iconv');
if (!@extension_loaded('iconv')) {
echo $strCantLoadRecodeIconv;
exit;
}
}
$PMA_recoding_engine = 'iconv';
} else {
if (@extension_loaded('iconv')) {
$PMA_recoding_engine = 'iconv';
} elseif (@extension_loaded('recode')) {
$PMA_recoding_engine = 'recode';
} else {
PMA_dl('iconv');
if (!@extension_loaded('iconv')) {
PMA_dl('recode');
if (!@extension_loaded('recode')) {
echo $strCantLoadRecodeIconv;
exit;
} else {
$PMA_recoding_engine = 'recode';
}
} else {
$PMA_recoding_engine = 'iconv';
}
}
}
} // end load recode/iconv extension
define('PMA_CHARSET_NONE', 0);
define('PMA_CHARSET_ICONV', 1);
define('PMA_CHARSET_LIBICONV', 2);
define('PMA_CHARSET_RECODE', 3);
if (!isset($cfg['IconvExtraParams'])) {
$cfg['IconvExtraParams'] = '';
}
// Finally detects which function will we use:
if (isset($cfg['AllowAnywhereRecoding'])
&& $cfg['AllowAnywhereRecoding']
&& $allow_recoding) {
if (!isset($PMA_recoding_engine)) {
$PMA_recoding_engine = $cfg['RecodingEngine'];
}
if ($PMA_recoding_engine == 'iconv') {
if (@function_exists('iconv')) {
$PMA_recoding_engine = PMA_CHARSET_ICONV;
} elseif (@function_exists('libiconv')) {
$PMA_recoding_engine = PMA_CHARSET_LIBICONV;
} else {
$PMA_recoding_engine = PMA_CHARSET_NONE;
if (!isset($GLOBALS['is_header_sent'])) {
include('./libraries/header.inc.php');
}
echo $strCantUseRecodeIconv;
require_once('./libraries/footer.inc.php');
exit();
}
} elseif ($PMA_recoding_engine == 'recode') {
if (@function_exists('recode_string')) {
$PMA_recoding_engine = PMA_CHARSET_RECODE;
} else {
$PMA_recoding_engine = PMA_CHARSET_NONE;
require_once('./libraries/header.inc.php');
echo $strCantUseRecodeIconv;
require_once('./libraries/footer.inc.php');
exit;
}
} else {
if (@function_exists('iconv')) {
$PMA_recoding_engine = PMA_CHARSET_ICONV;
} elseif (@function_exists('libiconv')) {
$PMA_recoding_engine = PMA_CHARSET_LIBICONV;
} elseif (@function_exists('recode_string')) {
$PMA_recoding_engine = PMA_CHARSET_RECODE;
} else {
$PMA_recoding_engine = PMA_CHARSET_NONE;
require_once('./libraries/header.inc.php');
echo $strCantUseRecodeIconv;
require_once('./libraries/footer.inc.php');
exit;
}
}
} else {
$PMA_recoding_engine = PMA_CHARSET_NONE;
}
/**
* Converts encoding according to current settings.
*
* @param mixed what to convert (string or array of strings or object returned by my
sql_fetch_field)
*
* @return string converted string or array of strings
*
* @global array the configuration array
* @global boolean whether recoding is allowed or not
* @global string the current charset
* @global array the charset to convert to
*
* @access public
*
* @author nijel
*/
function PMA_convert_display_charset($what) {
global $cfg, $allow_recoding, $charset, $convcharset;
if (!(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)
|| $convcharset == $charset // rabus: if input and output charset are the same, we don't have to do anything...
// this constant is not defined before the login:
|| (defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION >= 40100) ) { // lem9: even if AllowAnywhereRecoding is TRUE, do not recode for MySQL >= 4.1.x since MySQL does the job
return $what;
} elseif (is_array($what)) {
$result = array();
foreach ($what AS $key => $val) {
if (is_string($val) || is_array($val)) {
if (is_string($key)) {
$result[PMA_convert_display_charset($key)] = PMA_convert_display_charset($val);
} else {
$result[$key] = PMA_convert_display_charset($val);
}
} else {
$result[$key] = $val;
}
} // end while
return $result;
} elseif (is_string($what)) {
switch