<?php
class BaseConvert {
private static $base = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
public static function encode($num, $b = 62) {
$r = $num % $b;
$res = self::$base[$r];
$q = floor($num / $b);
while ($q) {
$r = $q % $b;
$q = floor($q / $b);
$res = self::$base[$r] . $res;
}
return $res;
}
public static function decode($num, $b = 62) {
$limit = strlen($num);
$res = strpos(self::$base, $num[0]);
for ($i = 1; $i < $limit; $i++) {
$res = $b * $res + strpos(self::$base, $num[$i]);
}
return $res;
}
}
var_dump(BaseConvert::encode(124, 36), BaseConvert::decode('3g', 36));
Тоже самое стандартными средствами
<?php
var_dump(
base_convert(124, 10, 36),
base_convert('3g', 36, 10)
);