-
-
/*
- * php短网址生成
- * edit: bbs.it-home.org
- */
- class Base62{
- private static $base62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
-
- public static function encode($number, $encode = ''){
- while($number > 0){
- $mod = bcmod($number, 62);
- $encode .= self::$base62[$mod];
- $number = bcdiv(bcsub($number, $mod), 62);
-
- }
- return strrev($encode);
- }
-
- public static function decode($encode, $number = 0){
- $length = strlen($encode);
- $baselist = array_flip(str_split(self::$base62));
- for($i = 0; $i $number = bcadd($number, bcmul($baselist[$encode[$i]], bcpow(62, $length - $i - 1)));
- }
- return $number;
- }
- }
复制代码
|