Home > Backend Development > PHP Tutorial > json_encode PHP learning notes_encoding json_encode Chinese is not displayed

json_encode PHP learning notes_encoding json_encode Chinese is not displayed

WBOY
Release: 2016-07-29 08:47:17
Original
1015 people have browsed it

Found a solution online:

Copy the code The code is as follows:


/* Processing json_encode Chinese garbled characters*/
$data = array ('game' => 'The Kingdom of Ice and Fire ', 'name' => 'Thorn Spirit', 'country' => 'Frost Country', 'level' => 45 );
echo json_encode ( $data );
echo "
" ;
$newData = array ();
foreach ( $data as $key => $value ) {
$newData [$key] = urlencode ( $value );
}
echo urldecode ( json_encode ( $newData ) ) ;
?>


Later, I asked others for advice. Base64 encoding can also be used, but base64 encoding cannot be placed in the URL. Baidu explained this:
Standard Base64 is not suitable for transmission directly in the URL because The URL encoder will convert the "/" and "+" characters in standard Base64 into a form such as "%XX", and these "%" characters need to be converted when they are stored in the database, because ANSI SQL has Use the "%" sign as a wildcard character.
However, my data is sent via POST and is not in the HTTP head, but in the message-body, so it is not affected.
json_encode can only accept data in utf-8 format
urlencode base64_encode can only accept string type parameters, so the entire array cannot be encoded.

The above introduces json_encode PHP learning notes_Encoding json_encode Chinese is not displayed, including json_encode content. I hope it will be helpful to friends who are interested in PHP tutorials.

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