php 修改数据编码
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 );
}
return $arrayVal;
}
if (is_string ( $arrayVal )) {
$arrayVal = mb_convert_encoding ( $arrayVal, "GBK", $orgEncoding );
}
return $arrayVal;
}