Short web site has been popular for some time, used to do Sina Weibo application when there is contact, but did not make clear, and recently again contacted this dongdong, carefully studied the next, found that the short URL is also quite easy. The following will be the use of PHP to generate a short URL implementation method to do a record.
PHP generates a short domain name function
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21-22 |
Public Function Createrandcode ($string) {$code = '; $hex _code = ' 1qaz2wsx3edc4rfv5t-gb6yhn7ujm8ik9ol0p_ '; $now = Microti Me (TRUE) * 10000; $strlen = strlen ($hex _code); $hash _code = hash (' sha256 ', $string); This will define a random length for the encoding, depending on the step $step = rand (8, 16); $count = Ceil (strlen ($hash _code)/$step); for ($i = 0; $i < $count; $i + +) {$start = $i * $STEP; $hex _num = substr ($hash _code, $start, $step); $num = 0x3fffffff & Amp (1 * ' 0x '. $hex _num); $n = $num% $strlen; $code. = $hex _code[$n]; return $code; } |
The above is the article to share the entire content of the code, I hope you can enjoy.