Home > Article > Backend Development > Solution to php base64 decode garbled problem
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.
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!