Home > php教程 > php手册 > 解决 json_encode 中文乱码

解决 json_encode 中文乱码

WBOY
Release: 2016-06-13 09:42:31
Original
1235 people have browsed it

 

 

解决以下问题
  1. json_encode 中文后的字符串不可阅读
  2. json_encode 多级数组中文乱码问题
  3. json_encode 数组中包含换行时错误问题
  4. json_encode 数组中键为中文的问题
  5. http://blog.1dnet.net/?post=840
   

[PHP]代码

01 //http://blog.1dnet.net 02 function _encode($arr) 03 { 04   $na array(); 05   foreach $arr as $k => $value ) {   06     $na[_urlencode($k)] = _urlencode ($value);   07   } 08   return addcslashes(urldecode(json_encode($na)),"\r\n"); 09 } 10   11 function _urlencode($elem) 12 { 13   if(is_array($elem)){ 14     foreach($elem as $k=>$v){ 15       $na[_urlencode($k)] = _urlencode($v); 16     } 17     return $na; 18   } 19   return urlencode($elem); 20 }
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