Last active
August 8, 2024 11:02
-
-
Save ge0ffray/2048791 to your computer and use it in GitHub Desktop.
Check if a string seems to be base64 encoded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param string $str | |
* @return bool | |
*/ | |
function is_base64($str) | |
{ | |
return (bool)preg_match('`^[a-zA-Z0-9+/]+={0,2}$`', $str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A slightly adapted version incase anyone is validating base64 encoded files (not fully tested):