Skip to content

Instantly share code, notes, and snippets.

@fhefh2015
Last active April 9, 2018 01:33
Show Gist options
  • Save fhefh2015/0a6cdeaf015fe9fd93af31922a23e57f to your computer and use it in GitHub Desktop.
Save fhefh2015/0a6cdeaf015fe9fd93af31922a23e57f to your computer and use it in GitHub Desktop.
短网址ID生成
<?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