Do you have a particular reason for wanting to do it this way? Or are you trying to come up with a way to create unique file names? If its the latter, then have a look at PHP's uniqid function.
In that case, how about this, it doesn't fulfill all your requirements, but will get you much closer:
function createId($numId) {
$result = '';
$mod = 26;
$quotient = $numId;
while ($quotient >= 0) {
$result .= chr(65 + ($quotient % $mod));
$quotient = $quotient / $mod - 1;
}
return $result;
}
And with the following calls:
print createId(0) . "\n";
print createId(25) . "\n";
print createId(26) . "\n";
print createId(8) . "\n";
print createId(9876) . "\n";
gives you:
A
Z
AA
I
WON