I have a script:
function convert($src, $srcAlphabet = '0123456789', $dstAlphabet =
'qwertyuiopasdfghjklzxcvbnm')
{
$srcBase = strlen($srcAlphabet);
$dstBase = strlen($dstAlphabet);
$wet = $src;
$val = 0;
$mlt = 1;
while($l = strlen($wet))
{
$digit = $wet[$l - 1];
$val += $mlt * strpos($srcAlphabet, $digit);
$wet = substr($wet, 0, $l - 1);
$mlt *= $srcBase;
}
$wet = $val;
$dst = '';
while($wet >= $dstBase)
{
$digitVal = $wet % $dstBase;
$digit = $dstAlphabet[$digitVal];
$dst = $digit . $dst;
$wet /= $dstBase;
}
$digit = $dstAlphabet[$wet];
$dst = $digit . $dst;
return $dst;
}
for($i = 0; $i < 10000; $i++)
{
echo $i . ' = ' . convert(substr(' ' . $i, 1)) . '<br>';
}
It works fine, however the result is strange... it looks like that:
0 = q
1 = w
2 = e
3 = r
4 = t
5 = y
6 = u
7 = i
8 = o
9 = p
10 = a
11 = s
12 = d
13 = f
14 = g
15 = h
16 = j
17 = k
18 = l
19 = z
20 = x
21 = c
22 = v
23 = b
24 = n
25 = m
26 = wq
...
...
676 = wqq
677 = wqw
678 = wqe
...
but 26 should be qq, 676 should be qqq, 677 = qwq, 678 = qqe etc.
why it's starting from w instead of q (except for 0)?