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

How to solve the problem of php urldecode garbled characters

藏色散人
Release: 2023-03-08 09:24:01
Original
2031 people have browsed it

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();
Copy after login

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']);
Copy after login


Use urlencode to encode Chinese

The output is:

echo urldecode(json_encode($statuses));
Copy after login

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!

Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template