Home > Backend Development > PHP Tutorial > Solution to the problem that json_encode Chinese is encoded by Unicode in PHP

Solution to the problem that json_encode Chinese is encoded by Unicode in PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:11:18
Original
964 people have browsed it

First perform urlencode processing on the key values ​​​​of the array that needs to be processed, then json_encode, and finally urldecode processing.

<code><span><span>function</span><span>encode_json</span><span>(<span>$str</span>)</span> {</span><span>return</span> urldecode(json_encode(url_encode(<span>$str</span>)));   
}

<span>/**
 *@desc 递归的处理数组中的每一个键值对
 */</span><span><span>function</span><span>url_encode</span><span>(<span>$str</span>)</span> {</span><span>if</span>(is_array(<span>$str</span>)) {
        <span>foreach</span>(<span>$str</span><span>as</span><span>$key</span>=><span>$value</span>) {
            <span>$str</span>[urlencode(<span>$key</span>)] = url_encode(<span>$value</span>);
        }
    } <span>else</span> {
        <span>$str</span> = urlencode(<span>$str</span>);
    }

    <span>return</span><span>$str</span>;
}
</code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the solution to the Unicode encoding of json_encode Chinese in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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