Home  >  Article  >  Backend Development  >  PHP json_decode method cannot parse the special question mark character

PHP json_decode method cannot parse the special question mark character

一个新手
一个新手Original
2017-10-25 13:09:112218browse

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");

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!

Statement:
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