摘要:在读取sqlserver的时候由于字段是中文且中文的类型不唯一造成读取数据乱码
/**
* TODO 将一维的关联数组格式化编码
* @param array $data [description]
* @return [type] [description]
*/
function formating_encocode($data=array())
{
//设置输出方式
header('Content-Type:text/html; charset=utf-8');
foreach ($data as $key => $value) {
//查看是什么编码
$encode = mb_detect_encoding($value, array("ASCII",'UTF-8','GB2312',"GBK",'BIG5'));
//在这里对编码进行转换(顶部的header不能去掉,否则会出现乱码)
$trans=mb_convert_encoding($key,'UTF-8',"gb2312");
$return[$trans] = $value;
}
return $return;
}
/**
* TODO 将多维的关联数组格式化编码
* @param array $data [description]
* @return [type] [description]
*/
function formating_encocode_many($arr=array())
{
//设置输出方式
header('Content-Type:text/html; charset=utf-8');
foreach($arr as $k=>$v){
$end[$k] = formating_encocode($v);
}
return $end;
}