Home > Backend Development > PHP Problem > Solution to php base64 decode garbled problem

Solution to php base64 decode garbled problem

藏色散人
Release: 2023-03-04 13:42:01
Original
6077 people have browsed it

php The solution to base64 decode garbled code: first open the corresponding PHP file; then add the statement "$encodedData = str_replace(' ',$encodedData);" before using "base64_decode" to decode.

Solution to php base64 decode garbled problem

Recommendation: "PHP Video Tutorial"

Problems that occurred a few days ago, GET and POST The string in the request was garbled after being base64_decoded. I checked that it was a problem with PHP. Just add the sentence:

  $encodedData = str_replace(' ','+',$encodedData);
  $decocedData = base64_decode($encodedData);
Copy after login

before using base64_decode to decode.

If the string is too long, it needs to be replaced first and then decoded in segments:

$encoded = str_replace(' ','+',$encoded);
$decoded = ""; 
for ($i=0; $i < ceil(strlen($encoded)/256); $i++) 
   $decoded = $decoded . base64_decode(substr($encoded,$i*256,256));
Copy after login

The above is the detailed content of Solution to php base64 decode garbled problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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