导出文件在IE和火狐中文件名乱码问题的解决

$ua = $_SERVER["HTTP_USER_AGENT"];
		$filename = "客户数据.xls";
		$encoded_filename = urlencode($filename);
		$encoded_filename = str_replace("+", "%20", $encoded_filename);
		if (preg_match("/MSIE/", $ua)) {  
			header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
		} else if (preg_match("/Firefox/", $ua)) {  
			header('Content-Disposition: attachment; filename*="utf8\'\'' . $filename . '"');
		} else {  
			header('Content-Disposition: attachment; filename="' . $filename . '"');
		}


数据导出,会有一些乱码问题,这是google到的解决方案,针对IE和FF做了不同的处理,IE文件名需要urlencode处理,FF需要加utf8前缀,真不知道这两种浏览器这是什么怪脾气....

 

posted @ 2013-08-07 18:20  javawebsoa  Views(479)  Comments(0Edit  收藏  举报