代码:
//编码转换函数
public static function arrayValueToUtf8($arrayVal, $orgEncoding = "GBK") {
if (is_object ( $arrayVal )) {
$arrayVal = ( array ) $arrayVal;
}
if (is_array ( $arrayVal )) {
foreach ( $arrayVal as $key => $value ) {
$arrayVal [$key] = self::arrayValueToUtf8 ( $value );
}
return $arrayVal;
}
if (is_string ( $arrayVal )) {
$arrayVal = mb_convert_encoding ( $arrayVal, "UTF-8", $orgEncoding );
}
return $arrayVal;
}
/**
* 说明:为兼容mssql数据库,对写入数据库的数据进行编码转换
*
* @param array $arrayVal
* @param Sring $orgEncoding
*/
public static function arrayValueToGbk($arrayVal, $orgEncoding = "UTF-8") {
if (is_array ( $arrayVal )) {
foreach ( $arrayVal as $key => $value ) {
$arrayVal [$key] = self::arrayValueToGbk ( $value );
} // www.jb200.com
return $arrayVal;
}
if (is_string ( $arrayVal )) {
$arrayVal = mb_convert_encoding ( $arrayVal, "GBK", $orgEncoding );
}
return $arrayVal;
}