无为清净楼资源网 Design By www.qnjia.com
Base62类源码:
复制代码 代码如下:
class Base62 {

    private $string = "vPh7zZwA2LyU4bGq5tcVfIMxJi6XaSoK9CNp0OWljYTHQ8REnmu31BrdgeDkFs";

    public function base62_encode($str) {
        $out = '';
        for($t=floor(log10($str)/log10(62)); $t>=0; $t--) {
            $a = floor($str / pow(62, $t));
            $out = $out.substr($this->string, $a, 1);
            $str = $str - ($a * pow(62, $t));
        }  
        return $out;
    }  

    public function base62_decode($str) {
        $out = 0;
        $len = strlen($str) - 1;
        for($t=0; $t<=$len; $t++) {
            $out = $out + strpos($this->string, substr($str, $t, 1)) * pow(62, $len - $t);
        }  
        return substr(sprintf("%f", $out), 0, -7);
    }  
}

用法:
复制代码 代码如下:
$str = 1;
$object = new Base62();
echo $object->base62_encode($str) . "\n";
echo $object->base62_decode($object->base62_encode($str)) . "\n";
标签:
Base62类,数值转字符串

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com