服务器本地编码:GBK
response 编码:ISO-8859-1(tomcat服务器默认response 编码ISO-8859-1)
输出:GBK->ISO-8859-1
正确方法:
1、改变response编码 response.setCharacterEncoding("GBK");
2、String result = new String(str.getByte("GBK"),"ISO-8859-1");
输入:
1、如果response 是 ISO-8859-1:ISO-8859-1->GBK(这步是PHP自动的)
2、如果response 是 GBK:GBK->GBK(这步是PHP自动的)
php页面本身的编码:UTF-8
正确方法 GBK->UTF-8:mb_convert_encoding(file_get_contents($url),"UTF-8","GBK");

本文介绍了在不同编码环境下如何正确地进行字符编码转换,包括从GBK到ISO-8859-1及UTF-8的转换方法,并提供了具体的PHP实现示例。
1875

被折叠的 条评论
为什么被折叠?



