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);
?>

About sunny

sunny verma has written 66 post in this blog.

I am 26 years old php programmer from India.

Related posts:

  1. Convert Alphanumeric into Decimal using php
  2. Google advanced search Tips

  3 Responses to “Convert Decimal into Alphanumeric using php”

  1. 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.

  2. @Andy
    i will post that code soon

  3. Andy :

    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.

    find your code here http://www.webnol.org/convert-alphanumeric-into-decimal-using-php/

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
 
© 2012 A Guide to Technology Suffusion theme by Sayontan Sinha