Created
February 24, 2016 11:22
-
-
Save Foxy79/07a58168d281dcbba794 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 num2chars($n) { | |
$cs = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
$s = strlen($cs); | |
$str = ""; | |
while($n) { | |
$str = $cs{$n%$s}.$str; | |
$n = floor($n/$s); | |
} | |
if ($str == "") { return $cs{0}; } | |
return $str; | |
} | |
function chars2num($str) { | |
$cs = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
$s = strlen($cs); | |
$res = 0; | |
$a = str_split($str); | |
foreach ($a as $c) { $res = $res * $s + strrpos($cs,$c); } | |
return $res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment