The following describes the usage of Base62 in php.
The following describes the usage of Base62 in php.
Base62 class source code:
The Code is as follows:
Class Base62 {
Private $ string = "success ";
Public function base62_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 <= $ len; $ t ++ ){
$ Out = $ out + strpos ($ this-> string, substr ($ str, $ t, 1) * pow (62, $ len-$ t );
}
Return substr (sprintf ("% f", $ out), 0,-7 );
}
}
Usage:
The Code is as follows:
$ Str = 1;
$ Object = new Base62 ();
Echo $ object-> base62_encode ($ str). "\ n ";
Echo $ object-> base62_decode ($ object-> base62_encode ($ str). "\ n ";
, Record-free space, U.S. servers, U.S. servers