Is base 64 string encoded?

How to determine if a string is data encoded with the base64_encode() function or not?

Is it possible?

+6
php base64
source share
2 answers

Trying to decode it strictly against Base64 alphabet. The second parameter allows you to perform this rigorous check; Leaving this, the decoding function simply produces illegal characters before decoding:

 if (base64_decode($str, true) === false) { echo 'Not a Base64-encoded string'; } 
+17
source share

Try the following:

 if(base64_encode(base64_decode($img, true)) === $img) echo 'is a Base64-encoded string' ; 
+1
source share

All Articles