function gbk_to_utf8($str){ return mb_convert_encoding($str, 'utf-8', 'gbk'); } function utf8_to_gbk($str){ return mb_convert_encoding($str, 'gbk', 'utf-8'); }
<?php function characet($data){ if( !empty($data) ){ $fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ; if( $fileType != 'UTF-8'){ $data = mb_convert_encoding($data ,'utf-8' , $fileType); } } return $data; } ?>
public static function strToGBK($strText) { $encode = mb_detect_encoding($strText, array('UTF-8','GB2312','GBK')); if($encode == "UTF-8") { return @iconv('UTF-8','GB18030',$strText); } else { return $strText; } }