Home > Backend Development > PHP Tutorial > Solve json_encode Chinese garbled code_PHP tutorial

Solve json_encode Chinese garbled code_PHP tutorial

WBOY
Release: 2016-07-13 10:37:49
Original
1043 people have browsed it

 

 

Solve the following problems
  1. The string after json_encode Chinese cannot be read
  2. json_encode multi-level array Chinese garbled problem
  3. Error when json_encode array contains line breaks
  4. The problem with the keys in the json_encode array being Chinese
  5. http://blog.1dnet.net/?post=840
​ ​

[PHP]Code

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)),"rn"); 09 } 10<code>10   11<code>11 function<code class="keyword">function _urlencode(<code class="plain">_urlencode($elem<code class="variable">$elem)<code class="plain">) 12<code>12 {<code class="plain">{ 13<code>13   <code class="spaces">  if<code class="keyword">if(<code class="plain">(is_array<code class="functions">is_array(<code class="plain">($elem<code class="variable">$elem)){<code class="plain">)){ 14<code>14     <code class="spaces">    foreach<code class="keyword">foreach(<code class="plain">($elem<code class="variable">$elem as<code class="keyword">as $k<code class="variable">$k=><code class="plain">=>$v<code class="variable">$v){<code class="plain">){ 15<code>15       <code class="spaces">      $na<code class="variable">$na[_urlencode(<code class="plain">[_urlencode($k<code class="variable">$k)] = _urlencode(<code class="plain">)] = _urlencode($v<code class="variable">$v);<code class="plain">); 16<code>16     <code class="spaces">    }<code class="plain">} 17<code>17     <code class="spaces">    return<code class="keyword">return $na<code class="variable">$na;<code class="plain">; 18<code>18   <code class="spaces">  }<code class="plain">} 19<code>19   <code class="spaces">  return<code class="keyword">return urlencode(<code class="plain">urlencode($elem<code class="variable">$elem);<code class="plain">); 20<code>20 }<code class="plain">}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/735166.htmlTechArticle解决以下问题 json_encode 中文后的字符串不可阅读 json_encode 多级数组中文乱码问题 json_encode 数组中包含换行时错误问题 json_encode 数组中键为...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template