info about link
: Javascript : PHP Index : MySQL :
convert decimals 2 alphabet
: Source : : Explanation : : Example : : Todo : : Feedback :

Why this script

Some systems might use an alphabet based string (containing only the letters from the (english) alphabet) as a unique representation of an entity.
In database this would cause a huge problem if you actually relied on that in your datamodel, not to mention that you would have to write a lot of code to safeguard your data integrity.
With these to functions - convDec2Alpha & convAlpha2Dec - you need to worry no longer. You can just use an auto_increment field and let the convDec2Alpha function convert this primary key for you into an alphabetical representation. Or, given the alphabetical string, convert it back into a decimal.

Usage

To convert a decimal number into an alphabetical string use:
<?php
echo convDec2Alpha(1);
?>
This would output AA. The length of this string can be modified though, by the optional 2nd argument
<?php
echo convDec2Alpha(1, 3);
?>
Would output AAA

Other examples:
<?php
echo convDec2Alpha(1)."-".convDec2Alpha(3)."-".convDec2Alpha(27);
?>
would output AA-AC-BA

The reverse process can be accomplished by:
<?php
echo convAlpha2Dec("AA");
?>
This would output 1.
Similarly
<?php
echo convAlpha2Dec("AAA");
?>
would also output 1
=[Disclaimer]=     © 2005-2012 Excudo.net