Home > Backend Development > PHP Tutorial > PHP Learning Notes_Encoding (json_encode Chinese is not displayed)_PHP Tutorial

PHP Learning Notes_Encoding (json_encode Chinese is not displayed)_PHP Tutorial

WBOY
Release: 2016-07-21 15:23:04
Original
829 people have browsed it

Found a solution online:

Copy code The code is as follows:

/* Processing json_encode Chinese garbled code*/
$data = array ('game' => 'Ice and Fire Country', '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, and I can also use base64 encoding, 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 The 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 The "%" sign is used 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324558.htmlTechArticleI found a solution on the Internet: Copy the code as follows: ?php /* Process json_encode Chinese garbled characters*/ $ data = array ('game' = 'Ice and Fire Country', 'name' = 'Thorn Spirit', 'country' = 'Ice...
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