<?php
/*
* 
php短网址生成
* edit:  www.jb200.com
*/
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 < $length; $i++){
   $number = bcadd($number, bcmul($baselist[$encode[$i]],  bcpow(62, $length - $i - 1)));
  } 
  return $number;  
 } 
}