Skip to content

Instantly share code, notes, and snippets.

@jkoop
Last active May 13, 2025 15:39
Show Gist options
  • Save jkoop/01a689dfc1637e78c66e0fe7099cec17 to your computer and use it in GitHub Desktop.
Save jkoop/01a689dfc1637e78c66e0fe7099cec17 to your computer and use it in GitHub Desktop.
<?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