Base62 class Source:
Copy CodeThe code is as follows:
Class Base62 {
Private $string = "VPH7ZZWA2LYU4BGQ5TCVFIMXJI6XASOK9CNP0OWLJYTHQ8RENMU31BRDGEDKFS";
Public Function Base62_encode ($STR) {
$out = ";
For ($t =floor (log10 ($STR)/log10), $t >=0; $t-) {
$a = Floor ($str/pow (, $t));
$out = $out. substr ($this->string, $a, 1);
$str = $str-($a * POW ($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 ($len-$t);
}
Return substr (sprintf ("%f", $out), 0,-7);
}
}
usage:
Copy CodeThe code is as follows:
$STR = 1;
$object = new Base62 ();
echo $object->base62_encode ($STR). "\ n";
echo $object->base62_decode ($object->base62_encode ($STR)). "\ n";
http://www.bkjia.com/PHPjc/328183.html www.bkjia.com true http://www.bkjia.com/PHPjc/328183.html techarticle Base62 Class Source code: Copy the code as follows: Class Base62 {private $string = " Vph7zzwa2lyu4bgq5tcvfimxji6xasok9cnp0owljythq8renmu31brdgedkfs "; Public Function Base62_encode ($STR) ...