Home  >  Article  >  Backend Development  >  Solution to php base64 decode garbled problem

Solution to php base64 decode garbled problem

藏色散人
藏色散人Original
2020-08-15 09:26:365894browse

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

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

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!

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