龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

字符串编码 php字符串编码转换

时间:2014-06-21 15:47来源:网络整理 作者:网络 点击:
分享到:
php字符串编码转换 [代码片段(15行)]
php;toolbar:false;">function phpcharset($data, $to) {
    if(is_array($data)) {
        foreach($data as $key => $val) {
            $data[$key] = phpcharset($val, $to);
        }
    } else {
        $encode_array = array('ASCII', 'UTF-8', 'GBK', 'GB2312', 'BIG5');
        $encoded = mb_detect_encoding($data, $encode_array);
        $to = strtoupper($to);
        if($encoded != $to) {
            $data = mb_convert_encoding($data, $to, $encoded);
        }
    }
    return $data;
}
精彩图集

赞助商链接