


Solution to the problem that json_encode Chinese is encoded by Unicode in PHP
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>
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP's urldecode() function was created in PHP4 and is a common URL decoding method. URL encoding is a method of converting non-English characters in a URL into special characters in order to transmit the URL to the server or otherwise process the URL. The urldecode() function restores these special characters to the original string. The syntax of this function is: stringurldecode(string$str) parameter str represents the character that needs to be decoded

PHP's urlencode() function: How to encode a string into a URL-safe format, specific code examples are needed. With the development of the Internet, URLs are widely used in daily life, and we often need to encode strings with some special characters into URL-safe formats. Format to pass parameters in the URL or request a web page. PHP provides the urlencode() function to accomplish this task. This article will introduce the usage of urlencode() function and give some specific code examples. 1. ur

In modern development, passing data through URLs is a common way. However, because the URL may contain some special characters, such as spaces, slashes, and question marks, these special characters will destroy the structure of the URL and cause data transmission to fail. In order to avoid this situation, PHP provides the urlencode function, which can encode the URL into a transportable format. The use of the urlencode function is very simple. Its syntax is as follows: stringurlencode(string

The urldecode() function in PHP is used to decode the URL and restore the escaped characters to the original characters. When processing parameters in the URL, you often need to use the urldecode() function. The syntax of the urldecode() function is as follows: stringurldecode(string$str) where $str is the URL string to be decoded. The urldecode() function will replace %xx in the string with the corresponding characters, xx

Introduction to PHP functions—urlencode(): Encoding URLs When developing web applications, you often encounter situations where URLs need to be encoded. URL encoding ensures that special characters in URLs are passed correctly, avoiding problems or incorrect results. In PHP, we can use the urlencode() function to perform URL encoding. The function of urlencode() function is to convert the string into an encoding format that conforms to the URL specification. It converts non-alphanumeric characters in a string to

1The basic unit of Unicode computer storage is the byte, which is composed of 8 bits. Since English only consists of 26 letters plus a number of symbols, English characters can be stored directly in bytes. But other languages (such as Chinese, Japanese, Korean, etc.) have to use multiple bytes for encoding due to the large number of characters. With the spread of computer technology, non-Latin character encoding technology continues to develop, but there are still two major limitations: no multi-language support: the encoding scheme of one language cannot be used in another language and there is no unified standard: for example There are many encoding standards in Chinese such as GBK, GB2312, GB18030, etc. Since the encoding methods are not unified, developers need to convert back and forth between different encodings, and many errors will inevitably occur.

What are the similarities and differences between __str__ and __repr__? We all know the representation of strings. Python's built-in function repr() can express objects in the form of strings to facilitate our identification. This is the "string representation". repr() obtains the string representation of an object through the special method __repr__. If __repr__ is not implemented, when we print an instance of a vector to the console, the resulting string may be. >>>classExample:pass>>>print(str(Example()))>>>

Usage: 1. Used to encode dictionary; 2. Used to encode list; 3. Used to encode nested list; 4. Specify separator, etc.
