Created
September 19, 2012 04:55
-
-
Save CodeNegar/3747749 to your computer and use it in GitHub Desktop.
PHP: custom base, custom characters conver
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 shorten($id, $alphabet='0123456789abcdefghijklmnopqrstuvwxyz') | |
{ | |
$base = strlen($alphabet); | |
$short = ''; | |
while($id) { | |
$id = ($id-($r=$id%$base))/$base; | |
$short = $alphabet{$r} . $short; | |
}; | |
return $short; | |
} | |
echo shorten(587421554); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment