Home  >  Article  >  Backend Development  >  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
coldplay.xixiOriginal
2020-07-13 09:27:205567browse

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

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!

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