Skip to content

Instantly share code, notes, and snippets.

@CodeNegar
Created September 19, 2012 04:55
Show Gist options
  • Save CodeNegar/3747749 to your computer and use it in GitHub Desktop.
Save CodeNegar/3747749 to your computer and use it in GitHub Desktop.
PHP: custom base, custom characters conver
<?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