Base62クラスソースコード:
复制代代码如下:
class Base62 {
private $string = "vPh7zZwA2LyU4bGq5tcVfIMxJi6XaSoK9CNp0OWl jYTHQ8REnmu31BrdgeDkFs";
public functionbase62_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 $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)) 。 「ん」;
http://www.bkjia.com/PHPjc/328183.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/328183.html技術記事 Base62 ソースコード: 复制代価 代価例: class Base62 { private $string = "vPh7zZwA2LyU4bGq5tcVfIMxJi6XaSoK9CNp0OWljYTHQ8REnmu31BrdgeDkFs";パブリック関数base62_encode($str)...