Home > php教程 > php手册 > php用urlencode、urldecode解决汉字乱码问题

php用urlencode、urldecode解决汉字乱码问题

WBOY
Release: 2016-06-14 00:02:46
Original
1325 people have browsed it

有时候数据库中存了汉字,取出来之后变成了乱码,可以用urlencode、urldecode这两个函数来解决这个问题,例如:

$statuses=M('information_sheet')->where(array('Id'=>$newsid))->field('List_ID,Id,CreateDate,Theme,pic_urls')->find();我从表information_shee中取出了List_ID,Id,CreateDate,Theme,pic_urls这几个字段的数据,其中Theme这个字段的数据是汉字,如果我不做处理,直接echo json_encode()输出的话,就会得到乱码,可以这样解决:

$statuses[0]['Theme']=urlencode($statuses[0]['Theme']);   用urlencode对中文进行编码

输出的时候为:

echo urldecode(json_encode($statuses));  用urldecode解码,就可以得到正确的中文了

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template