php 短网址ID生成

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 短网址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/");

以上是关于php 短网址ID生成的主要内容,如果未能解决你的问题,请参考以下文章