Last active
July 9, 2024 08:18
-
-
Save gwarnants/2048791 to your computer and use it in GitHub Desktop.
Check if a string seems to be base64 encoded
This file contains 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
None of the answers worked for me. In my case it was the lack of spaces that I used to tell if it was base64 encoded
$teststring = substr($string,4,100);
$not64 = strpos($teststring," ");
It's not in a function, but it has worked for me. I'm sure people will tell me that it won't always work, but ALL of the functions suggested above returned false for me regardless of the string.