Skip to content

Instantly share code, notes, and snippets.

@kijtra kijtra/numalpha.php
Last active Sep 10, 2016

Embed
What would you like to do?
#PHP Numeric to Alphabet OR Alphabet to Numeric function very simple
<?php
function numalpha($value) {
if (ctype_digit((string) $value)) {
return strtr(base_convert($value, 10, 36), '0123456789', 'ABCDEFGHIJ');
} elseif (ctype_alpha($value)) {
return base_convert(strtr($value, 'ABCDEFGHIJ', '0123456789'), 36, 10);
}
return false;
}
/*
- Usage -
$num = '321654987';
$toStr = numalpha($num);
$toNum = numalpha($toStr);
var_dump([
'origin' => $num,
'toStr' => $toStr,
'toNum' => $toNum
]);
- Result -
array(3) {
["origin"]=> string(9) "321654987"
["toStr"]=> string(6) "FbiGkr"
["toNum"]=> string(9) "321654987"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.