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'; }
Boltclock
source share