PHP json_decode method cannot parse the special question mark character

一个新手
Release: 2023-03-16 18:54:02
Original
2071 people have browsed it

When requesting information through other people's interfaces, occasionally encountering some characters, such as the following situation, null will be returned through json_decode

However, this situation is usually not due to the overall encoding problem. Because when parsing, it is parsed in UTF-8 encoding

. In this case, Chinese and English usually coexist, but some blank characters cannot be recognized.

Through the observation of the system logic, it should be due to the presence of characters that are not recognized by utf-8 when saving characters in the previous section. This situation is not affected in json_encode, so it directly leads to the interface to obtain data. Illegal characters appear when

Solution:

$return_data=mb_convert_encoding($return_data, "UTF-8","UTF-8");
Copy after login

Forcibly encode the characters returned through the curl request. In this case, the original utf-8 encoded text will not be affected. , at the same time, characters that cannot be recognized by utf-8 will be forced to be parsed, and the parsed characters will become English symbols?,

In this way, json_decode can be smoothly performed

The above is the detailed content of PHP json_decode method cannot parse the special question mark character. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!