IE浏览器用GET方式传递中文字符出现乱码问题的解决方法

昨天编码发现GET方式传递中文字符,后台接收以后显示乱码,换了chrome和Firefox浏览器均无此现象。经网络多方查询,分析是IE浏览器传递参数时采用编码为gb2312,然后台编码格式为UTF8,所以出现乱码。 chrome

综合网上多位同窗的方案,最后采用以下方式得以解决:(PHP语言). getBrowser函数为网络搜索获得,忘记出处没法注明,见谅。 数组

        $browser = getBrowser();
        if ($browser[0] == "Internet Explorer" ) {
        $xx= iconv("gb2312","utf-8", $xx); 
        // 或者 $xx= mb_convert_encoding($xx,"utf-8", "gb2312");  
        } 浏览器

//查询浏览器类型,返回的数组第一个为浏览器名称,第二个是版本号。
function getBrowser(){
$sys = $_SERVER['HTTP_USER_AGENT'];
if(stripos($sys, "NetCaptor") > 0){
  $exp[0] = "NetCaptor";
  $exp[1] = "";
}elseif(stripos($sys, "Firefox/") > 0){
  preg_match("/Firefox\/([^;)]+)+/i", $sys, $b);
  $exp[0] = "Mozilla Firefox";
  $exp[1] = $b[1];
}elseif(stripos($sys, "MAXTHON") > 0){
  preg_match("/MAXTHON\s+([^;)]+)+/i", $sys, $b);
  preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie);
 // $exp = $b[0]." (IE".$ie[1].")";
  $exp[0] = $b[0]." (IE".$ie[1].")";
  $exp[1] = $ie[1];
}elseif(stripos($sys, "MSIE") > 0){
  preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie);
  //$exp = "Internet Explorer ".$ie[1];
  $exp[0] = "Internet Explorer";
  $exp[1] = $ie[1];
}elseif(stripos($sys, "Netscape") > 0){
  $exp[0] = "Netscape";
  $exp[1] = "";
}elseif(stripos($sys, "Opera") > 0){
  $exp[0] = "Opera";
  $exp[1] = "";
}elseif(stripos($sys, "Chrome") > 0){
   $exp[0] = "Chrome";
   $exp[1] = "";
}else{
  $exp = "未知浏览器";
  $exp[1] = "";
}
return $exp;
} 网络

相关文章
相关标签/搜索