Klathmon code is good, but has some bugs:
The first is the alphabet
It is: ./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ Should be: ./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
Second order of characters / numbers
It generates for example: ...z But it should generate: z...
Improved code:
function base64_int_encode($num) { $alphabet_raw='./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; $alphabet=str_split($alphabet_raw); $arr=array(); $base=sizeof($alphabet); while($num) { $rem=$num % $base; $num=(int)($num / $base); $arr[]=$alphabet[$rem]; } $string=implode($arr); return str_pad($string, 4, '.', STR_PAD_RIGHT); }
source share