Perform crc32 verification on the original website to obtain the verification code. use sprintf to convert the verification code to an unsigned number. for detailed steps, see php to generate a short website.
Principle:
1. perform crc32 verification on the original website to obtain the verification code.
2. use sprintf ('% u') to convert the verification code to an unsigned number.
3. perform the remainder 62 operation on the unsigned number (uppercase and lowercase letters + digits are equal to 62 digits). after the remainder is obtained, it is mapped to 62 characters and the mapped characters are saved. (For example, if the remainder is 10, the ing character is A, 0-9 corresponds to 0-9, 10-35 corresponds to the A-Z, 35-62 corresponds to a-z)
4. perform cyclic operations until the value is 0.
5. concatenate all ing characters, that is, the code after the short URL.
The code is as follows:
The code is as follows:
/** Generate a short URL
* @ Param String $ original url
* @ Return String
*/
Function dwz ($ url ){
$ Code = sprintf ('% u', crc32 ($ url ));
$ Surl = '';
While ($ code ){
$ Mod = $ code % 62;
If ($ mod> 9 & $ mod <= 35 ){
$ Mod = chr ($ mod + 55 );
} Elseif ($ mod> 35 ){
$ Mod = chr ($ mod + 61 );
}
$ Surl. = $ mod;
$ Code = floor ($ code/62 );
}
Return $ surl;
}