版权声明:转载请注明来源,http://blog.csdn.net/u010071211 https://blog.csdn.net/u010071211/article/details/85115195
百度出来的无法使用,只好自己写,有bug的地方欢迎留言,感谢
function from62to10($str){
$dict = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$len = strlen($str);
$dec = 0;
for($i = 0;$i<$len;$i++){
//找到对应字典的下标
$pos = strpos($dict, $str[$i]);
$dec += $pos*pow(62,$len-$i-1);
}
return $dec;
}
echo from62to10('6r2HqO');
echo '<br>';
$dec = '5896401674';
function from10to62($dec) {
$dict = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$result = '';
do {
$result = $dict[$dec % 62] . $result;
$dec = intval($dec / 62);
} while ($dec != 0);
return $result;
}
echo from10to62($dec);