缩短

function shorturl($url)
{
    $url = crc32($url);
    $result = sprintf("%u", $url);
    return code62($result);
}
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;
}

 

posted @ 2021-07-29 18:14  酷酷的城池  阅读(87)  评论(0编辑  收藏  举报