PHP 字符编码
问题:
页面使用utf8编码
当网页刷新时,如果url中存在中文,会自动按 gb2313编码成
链接地址
http://localhost/cetcit/news/list.php?catid=79&cat2=电源
在浏览器中输入以上网址,转到后变成下面这样
http://localhost/cetcit/news/list.php?catid=79&cat2=%B5%E7%D4%B4
解决:
//首先将字符串转换成gb2312,然后进行编码,则链接地址都为编码后的地址
urlencode(mb_convert_encoding($t[category2],'gb2312','utf8'))
//http://localhost/cetcit/news/list.php?catid=79&cat2=%B5%E7%D4%B4
//然后在处理时再解码
urldecode(mb_convert_encoding($cat2,"utf8","gb2312"));
mb_convert_encoding("呵呵",'gb2312','utf8') //将字符串从utf8 转为gb312