Home  >  Article  >  Backend Development  >  php相关有关问题,高手帮忙讲解一下原理

php相关有关问题,高手帮忙讲解一下原理

WBOY
WBOYOriginal
2016-06-13 10:17:581065browse

php相关问题,高手帮忙讲解一下原理
为什么url编码后,然后再解码就不会出现‘\u51b0\u706b\u56fd\u5ea6’这类字符呢?

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $data = array(‘game’ => ‘冰火国度’,‘name’ =>  ‘刺之灵’,‘country’ => ‘冰霜国’,‘level’ => 45);echo json_encode( $data );echo ‘<br>’;/*** 处理json_encode乱码*/$newData = array();foreach( $data as $key => $value ){$newData[ $key ] = urlencode( $value );}echo urldecode( json_encode( $newData ) );?>结果显示:{“game”:”\u51b0\u706b\u56fd\u5ea6″,”name”:”\u523a\u4e4b\u7075″,”country”:”\u51b0\u971c\u56fd”,”level”:45}{“game”:”冰火国度”,”name”:”刺之灵”,”country”:”冰霜国”,”level”:”45″}


------解决方案--------------------
那你也没有编码之后打印啊,你编码之后立即又解码打印当然没有问题,urlencode把字节都编成普通ascii字符了,必须没有问题。
Statement:
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