Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavMorr/93268e3eb753ea00512d32e6b236e878 to your computer and use it in GitHub Desktop.
Save DavMorr/93268e3eb753ea00512d32e6b236e878 to your computer and use it in GitHub Desktop.
Generate a number from an alphanumeric string. Has limited utility and no suggestion of identity uniqueness.
<?php
function getNumKey($str) {
$alpha = range('A', 'Z');
$chars = str_split(strtoupper($str));
foreach ($chars as $char) {
$x = (is_numeric($char)) ? $char : (array_search($char, $alpha) + 1);
$numz += $x;
// echo $x.' ';
}
return $numz;
}
$str = 'CHCH1CH2DKDK4';
$numkey = getNumKey($str);
// echo '<hr>' . $numkey;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment