昨天編碼發現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;
} 網絡