一、基类方法:定义字符串、编写转换方法 class NumberHelper { public static $str="abcdefghijklmnopqrstuvwxyz6789ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
/** * Param:将数字转为短字符串 * @param $number * @return string */ public static function generate_code($number) { $out = ""; $codes = self::$str; while ($number > 61) { $m = $number % 62; $out = $codes[$m].$out; $number = ($number - $m) / 62; } return $codes[$number].$out; } /** * Param:将短字符串转为数字 * @param $string * @return float|int */ public static function get_num($string){ $codes = self::$str; $num = 0; for($i=0;$i<strlen($string);$i++){ $n = strlen($string) - $i -1; $pos = strpos($codes,$string[$i]); $num += $pos * pow(62, $n); } return $num; }
}
二、调用转换方法,根据自己定的规则,生成自己需要的短链接
public static function getSh