今天在做接口的时候,遇到在url里带参数时,当传入中文字符,用PHP接收解析出来的是乱码。怎么解决呢?方法很简单,只要使用php内置的mb_convert_encoding()方法就可以搞定。
补充:
在不同语言通讯开发时,遇到传递中文字符乱码时,解决方法为:
发送方 用rawurlencode() 或urlencode()方法转换成百分号(%)后跟两位十六进制数;
接收方 用rawurldecode() 或 urldecode()方法解码就欧了。
rawurlencode与urlencode的区别是:urlencode能把空格编码为加号(+)。
$temp= mb_convert_encoding($str, "UTF-8", "gb2312");
补充:
在不同语言通讯开发时,遇到传递中文字符乱码时,解决方法为:
发送方 用rawurlencode() 或urlencode()方法转换成百分号(%)后跟两位十六进制数;
接收方 用rawurldecode() 或 urldecode()方法解码就欧了。
rawurlencode与urlencode的区别是:urlencode能把空格编码为加号(+)。