一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Python和php之间通信中文乱码解决办法

时间:2014-03-26 编辑:简简单单 来源:一聚教程网

即使在urlencode之前str.decode(“cp936″).encode(“utf-8″)做了编码转换也是没用的。后来查询手册查到一个urllib.quote()函数,用此方法成功解决!
python端:

 代码如下 复制代码
str = "中文"
str = urllib.quote(str.decode("cp936").encode("utf-8"))
postData = {}
postData['str'] = str

...post请求发送代码...

php端:

 代码如下 复制代码
$str = urldecode($_POST['str'])
echo $str;

完美解决乱码问题!

热门栏目