Skip to content

Instantly share code, notes, and snippets.

@Foxy79
Created February 24, 2016 11:22
Show Gist options
  • Save Foxy79/07a58168d281dcbba794 to your computer and use it in GitHub Desktop.
Save Foxy79/07a58168d281dcbba794 to your computer and use it in GitHub Desktop.
<?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