Php generates short URLs
Copy codeThe Code is as follows:
<? Php
$ Chars = array ("a", "B", "c", "d", "e", "f", "g", "h ",
"I", "j", "k", "l", "m", "n", "o", "p ",
"Q", "r", "s", "t", "u", "v", "w", "x ",
"Y", "z", "0", "1", "2", "3", "4", "5 ",
"6", "7", "8", "9", "A", "B", "C", "D ",
"E", "F", "G", "H", "I", "J", "K", "L ",
"M", "N", "O", "P", "Q", "R", "S", "T ",
"U", "V", "W", "X", "Y", "Z ");
$ Salt = "www.joneto.com ";
$ Hash = MD5. ("http://www.sina.com". $ salt );
$ Rs = array ();
For ($ I = 0; $ I <4; $ I ++ ){
$ Temp = substr ($ hash, $ I * 8 );
$ Temp = base_convert ($ temp, 16, 10) & base_convert ("3 fffffff", 16, 10 );
$ Str = "";
For ($ j = 0; $ j <6; $ j ++ ){
$ Subtemp = $ temp & intval (base_convert ("3d", 16, 10 ));
$ Str. = $ chars [$ subtemp];
$ Temp = $ temp> 5;
}
Unset ($ temp );
$ Rs [] = $ str;
}
Print_r ($ rs );
?>