php 对任意维数组转换字符编码(扩展iconv)
对任意维数组转换字符编码(扩展iconv) [代码片段(30行)]
function mult_iconv($in_charset,$out_charset,$data)
{
if(substr($out_charset,-8)=='//IGNORE'){
$out_charset=substr($out_charset,0,-8);
}
if(is_array($data)){
foreach($data as $key => $value){
if(is_array($value)){
$key=iconv($in_charset,$out_charset.'//IGNORE',$key);
$rtn[$key]=mult_iconv($in_charset,$out_charset,$value);
}elseif(is_string($key) || is_string($value)){
if(is_string($key)){
$key=iconv($in_charset,$out_charset.'//IGNORE',$key);
}
if(is_string($value)){
$value=iconv($in_charset,$out_charset.'//IGNORE',$value);
}
$rtn[$key]=$value;
}else{
$rtn[$key]=$value;
}
}
}elseif(is_string($data)){
$rtn=iconv($in_charset,$out_charset.'//IGNORE',$data);
}else{
$rtn=$data;
}
return $rtn;
}
//该片段来自于http://outofmemory.cn
- 上一篇:php 删除utf-8 BOM
- 下一篇:php 判断访问IP
精彩图集
精彩文章






