PHP transfers the numeric ID to the letter Id
PHP transfers the numeric ID to the letter Id
ID is a frequent occurrence of the site, it is generally a number, but we found that many of the current site ID are letters, such as YouTube's video playback page its URL is similar to/WATCH?V=YZNJIBEDYWW. Here's a way to generate a letter ID.
Examples of Use:
echo Alphaid (12354); Qnd Echo alphaid (' Qnd ', true);//12354 Echo Alphaid (12354,false,6);//qndaab
Source:
PPQXN7COF * * Specifiying The second argument true, it'll * translate back e.g.: * PPQXN7COF-9007199254740989 * * This function was based on Any2dec && dec2any by * Fragmer[at]mail[dot]ru * see:http://nl3.php.net/manual/en/fun ction.base-convert.php#52450 * * If you want the alphaid to being at least 3 letter long, use the * $pad _up = 3 Argument * * In the most cases the better than totally random ID generators * Because this can easily avoid duplicate ID ' s. * For example if your correlate the Alpha ID to a auto incrementing ID * in your database, your ' re done. * * The reverse is do because it makes it slightly more cryptic, * but it also makes it easier to spread lots of IDs in Different * directories on your filesystem. Example: * $part 1 = substr ($alpha _id,0,1); * $part 2 = substr ($alpha _id,1,1); * $part 3 = substr ($alpha _id,2,strlen ($alpha _id)); * $destindir = "/". $part 1. " /". $part 2." /". $part 3; *//By reversing, directories is more evenly spread out. The *//First 26Directories already occupy to main levels * * More info on limitation: *-HTTP://BLADE.NAGAOKAUT.AC.JP/CGI-BIN/SCAT.RB/RU by/ruby-talk/165372 * * If you really need this for bigger numbers you probably has to look * at things like:http://thes erverpages.com/php/manual/en/ref.bc.php * or:http://theserverpages.com/php/manual/en/ref.gmp.php * but I haven ' t Really dugg into this. If you had more info on those * matters feel free to leave a comment. * * @author Kevin van Zonneveld <[email protected]> * @author Simon Franz * @author deadfish * @copyright 20 Kevin van Zonneveld (http://kevin.vanzonneveld.net) * @license http://www.opensource.org/licenses/bsd-license.php New BSD Licence * @version svn:release: $Id: alphaID.inc.php 344 2009-06-10 17:43:59z Kevin $ * @link HTTP://KEVIN.V anzonneveld.net/* * @param mixed $in String or long input to translate * @param boolean $to _num reverses Translatio n When True * @param mixed $pad _up number or Boolean Padds tHe result up to a specified length * @param string $passKey supplying a password makes it harder to calculate the Origina L ID * * @return mixed string or long */function alphaid ($in, $to _num = False, $pad _up = false, $passKey = null) {$index = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; if ($passKey!== null) {//Although this function ' s purpose are to just make the//ID Short-and don't so much secur E,//With this patch by Simon Franz (http://blog.snaky.org/)//You can optionally supply a password to make it har Der/To calculate the corresponding numeric ID for ($n = 0; $n
0) {$out-= POW ($base, $pad _up); }} $out = sprintf ('%F ', $out); $out = substr ($out, 0, Strpos ($out, '. ')); } else {//Digital number-->> alphabet letter code if (Is_numeric ($pad _up)) {$pad _up--; if ($pad _up > 0) {$in + = Pow ($base, $pad _up); }} $out = ""; for ($t = Floor (log ($in, $base)), $t >= 0; $t-) {$bcp = Bcpow ($base, $t); $a = Floor ($in/$bcp)% $base; $out = $out. substr ($index, $a, 1); $in = $in-($a * $bcp); } $out = Strrev ($out); Reverse} return $out;}