php相关问题,高手帮忙讲解一下原理
为什么url编码后,然后再解码就不会出现‘\u51b0\u706b\u56fd\u5ea6’这类字符呢?
<!-- 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″}