Home > Backend Development > PHP Problem > What should I do if I decode garbled characters after PHP base64 encoding?

What should I do if I decode garbled characters after PHP base64 encoding?

coldplay.xixi
Release: 2023-03-02 12:52:01
Original
5619 people have browsed it

The solution to decoding garbled characters after PHP base64 encoding: When passing in GET form, just prevent the [ ] sign from being replaced with a space. The code is [$str = base64_decode(str_replace(" "," ",$ _GET['str']))].

What should I do if I decode garbled characters after PHP base64 encoding?

##Solution to decoding garbled characters after PHP base64 encoding:

Sometimes use

base64_encode After encryption, it is transmitted to other pages in the form of GET. When decrypted with base64_decode, garbled characters appear.

When I encountered this problem, I was wondering why some could be decrypted correctly, but some were garbled?

After checking later, I found that there were some Chinese characters,

When passed in the form of GET, will be replaced with spaces .

In order to prevent garbled characters from appearing, I made a one-step substitution and then decrypted it. Sure enough, the problem of garbled characters no longer exists!

Now the problem is very simple, just write more Just one step

$str = base64_decode(str_replace(" ","+",$_GET['str']));
Copy after login

Related learning recommendations:

PHP programming from entry to master

The above is the detailed content of What should I do if I decode garbled characters after PHP base64 encoding?. 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