Last active
September 10, 2016 15:06
-
-
Save kijtra/a54fe198df1829ec142cf03c5d1ac63e to your computer and use it in GitHub Desktop.
#PHP Numeric to Alphabet OR Alphabet to Numeric function very simple
This file contains 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 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