What to do if php decode is garbled

藏色散人
Release: 2023-03-17 10:16:01
Original
1859 people have browsed it

php decode is garbled because the "json_encode()" function can only encode UTF-8 characters. The solution is: 1. Before encoding, the Chinese character encoding needs to be converted into UTF-8 format; 2. Just use encode again.

What to do if php decode is garbled

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

What should I do if php decode is garbled?

Because the json_encode() function can only encode UTF-8 characters, that is to say, the parameters you pass in to it can only be in UTF-8 format.

So, before you encode, you need to convert your Chinese character encoding into utf-8 format, and then encode again, so there will be no problem.

Related introduction:

json_encode - JSON encoding of variables

Description

json_encode(mixed $value, int $flags = 0, int $depth = 512): string|false
Copy after login

Returns a string, including the representation of value in JSON form. If the argument is an array or object, it will be serialized recursively.

If the value to be serialized is an object, only publicly visible properties are included by default, or the class can implement JsonSerializable to control how its value is serialized to JSON.

The encoding is affected by the passed flags parameter. In addition, the encoding of floating point values ​​depends on serialize_precision.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php decode is garbled. For more information, please follow other related articles on the PHP Chinese website!

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