Ideas:
1) Generate a 32-bit signature string from md5 of the long URL, divided into 4 segments, each segment is 8 bytes;
2) Process these four segments in a loop and take 8 bytes, Think of it as a hexadecimal string and 0x3fffffff (30 bits 1) and operate, that is, more than 30 bits are ignored;
3) These 30 bits are divided into 6 segments, and each 5-digit number is used as an index of the alphabet to obtain a specific Characters, proceed in sequence to obtain 6-digit strings;
4) The total md5 string can obtain 4 6-digit strings; any one of them can be used as the short url address of this long url;
The following is PHP code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Result:
1 2 3 4 5 6 |
|
The above introduces the PHP version of the Weibo short link algorithm, including the content of Weibo short links. I hope it will be helpful to friends who are interested in PHP tutorials.