| Code: |
| function dec2any( $num, $base=62, $index=false )
{ if (! $base ) { $base = strlen( $index ); } else if (! $index ) { $index = substr( "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ,0 ,$base ); } $out = ""; for ( $t = floor( log10( $num ) / log10( $base ) ); $t >= 0; $t-- ) { $a = floor( $num / pow( $base, $t ) ); $out = $out . substr( $index, $a, 1 ); $num = $num - ( $a * pow( $base, $t ) ); } return $out; } |
the following returns 00 while it should return 1000
| Code: |
| dec2any(46656 , 36); |
(i dont want to use base_convert because of its certain limitation, and this is the best what i got on the web. if you have better alternative or solution in mind, please suggest me).
