Last active
May 13, 2025 15:39
-
-
Save jkoop/01a689dfc1637e78c66e0fe7099cec17 to your computer and use it in GitHub Desktop.
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 | |
function crockford32_normalize(string $string): string|null { | |
$string = strtoupper($string); | |
$string = str_replace( | |
search: ["O", "I", "L", "U"], // this U replacement is non-standard | |
replace: ["0", "1", "1", "V"], | |
subject: $string, | |
); | |
if (preg_match("/[^0-9A-HJKMNP-TV-Z]/", $string)) { | |
return null; // input string contained invalid chars | |
} | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment