欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP生成短地址

程序员文章站 2022-04-26 11:58:51
...




urlShort









php code

header("Content-Type:text/html;charset=UTF-8");
function base62($x){
$show = '';
while($x>0){
$s = $x % 62;
if ($s > 35){
$s = chr($s + 61);
}else if ($s > 5 && $S $s = chr($s + 55);
}
$show .= $s;
$x = floor($x/62);
}
return $show;
}
function url_short($url){
$url = crc32($url);
$result = sprintf("%u",$url);
return base62($result);
}
echo ("生成的新网址为:".url_short($_POST['url'])."");