A Problem occurred when I was writing a script for shortUrl redirection. That using 5 Digit decimal numbers can cover only 105=100000 Urls but 5 digit alphanumeric (case sensitive) numbers are able to cover 622=916132832. So it is very helpful to keep Urls short.
Example
- Using Decimal http://surl.bz/0 to http://surl.bz/99999 only 100000 Urls In 5 Digit
- Using alphanumeric http://surl.bz/0 to http://surl.bz/ZZZZZ 916132832 Urls that’s Great choice
You can use this script to convert any decimal number into case sensitive alphanumeric number. This script is useful to create short profile id for you registered user like http://www.yourdomain.com/profile/AS34G or any unique id while keeping Url short.
<?php
function alphanumeric($dec)
{
$an="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$id="";
$base=62;
while($dec>=$base)
{
$mod=$dec%$base;
$id=$an[$mod].$id;
$dec=$dec/$base;
}
$id=$an[$dec].$id;
return $id;
}
echo alphanumeric(123456);
?>
Related posts:
hi sunny, your code is nice! I want to ask you, how to retrieve the numbers that have been converted to alphanumeric. For example, I want to get the number “123456 ” which has been converted into “w7e”. thank you.
@Andy
i will post that code soon
find your code here http://www.webnol.org/convert-alphanumeric-into-decimal-using-php/