Home > Article > Backend Development > Solution to the problem that json_decode cannot parse the special question mark character in PHP
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 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. The parsed characters will become English symbols?
In this way, json_decode can be smoothly performed
The above is the detailed content of Solution to the problem that json_decode cannot parse the special question mark character in PHP. For more information, please follow other related articles on the PHP Chinese website!