Home  >  Article  >  Backend Development  >  How to solve the problem of php urldecode garbled characters

How to solve the problem of php urldecode garbled characters

藏色散人
藏色散人Original
2021-02-25 09:13:551896browse

Solution to php urldecode garbled code: First open the corresponding PHP code file; then pass "$statuses[0]['Theme']=urlencode($statuses[0]['Theme']);" This method can solve the problem of garbled output.

How to solve the problem of php urldecode garbled characters

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php uses urlencode and urldecode to solve Chinese character garbled characters Problem

Sometimes Chinese characters are stored in the database and become garbled after being taken out. You can use the two functions urlencode and urldecode to solve this problem, for example:

$statuses=M('information_sheet')->where(array('Id'=>$newsid))->field('List_ID,Id,CreateDate,Theme,pic_urls')->find();

I The data in the fields List_ID, Id, CreateDate, Theme, and pic_urls were taken out from the table information_shee. The data in the Theme field is Chinese characters. If I don’t do any processing and directly output echo json_encode(), I will get garbled characters. It can be solved like this:

$statuses[0]['Theme']=urlencode($statuses[0]['Theme']);


Use urlencode to encode Chinese

The output is:

echo urldecode(json_encode($statuses));

Use urldecode to decode, that’s it Got the correct Chinese

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to solve the problem of php urldecode garbled characters. 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