一个php短网址的生成代码(仿微博短网址)_PHP教程
程序员文章站
2022-06-05 13:26:35
...
分享一个php短网址的生成代码。
urlShort
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);
} www.jbxue.com
$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'])."");
复制代码 代码如下:
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);
} www.jbxue.com
$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'])."");