Last active
April 9, 2018 01:33
-
-
Save fhefh2015/0a6cdeaf015fe9fd93af31922a23e57f to your computer and use it in GitHub Desktop.
短网址ID生成
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: fhefh | |
* Date: 18/4/8 | |
* Time: 下午11:37 | |
*/ | |
function code62($x) | |
{ | |
$show = ''; | |
while ($x > 0) { | |
$s = $x % 62; | |
if ($s > 35) { | |
$s = chr($s + 61); | |
} elseif ($s > 9 && $s <= 35) { | |
$s = chr($s + 55); | |
} | |
$show .= $s; | |
$x = floor($x / 62); | |
} | |
return $show; | |
} | |
function short_url_id($url) | |
{ | |
$url = crc32($url); | |
$result = sprintf("%u", $url); | |
return code62($result); | |
} | |
echo short_url_id("http://www.qq.com/"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment