Created
April 4, 2023 14:42
-
-
Save mdurys/cdf1f7acab9e94b1f7f0f90598f3f319 to your computer and use it in GitHub Desktop.
Check if given string is 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
| private static function isBase64Encoded(string $text): bool | |
| { | |
| if (false === $decoded = base64_decode($text, true)) { | |
| return false; | |
| } | |
| // check if decoded text consists only of unicode letters, digits and white space | |
| if (!preg_match('|^[\p{L}\d\s]+$|u', $decoded)) { | |
| return false; | |
| } | |
| return $text === base64_encode($decoded); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment