下面例程一和例程二是相同效果 例程一: <?php header("content-type:text/html;charset=utf-8"); $str=file_get_contents('json.txt'); //array('ASCII','GB2312','UTF-8') 字符串编码类型数组 $type_arr= array('ASCII','GB2312','UTF-8'); $enc_type=mb_detect_encoding($str,$type_arr); //从给出的 字符串编码类型数组中,检查当前字符串$str的编码类型 $str_utf8=iconv($enc_type,'utf-8',$str);//$enc_type是输入字符串编码类型 var_dump($str_utf8); ?> 例程二: <?php header("content-type:text/html;charset=utf-8"); $str=file_get_contents('json.txt'); $str_utf8= mb_convert_encoding($str, 'utf-8','ASCII,GB2312,UTF-8'); var_dump($str_utf8); ?> |
|