分享一个php短网址的生成代码。
复制代码 代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>urlShort</title>
</head>
<body>
<form action="urlShort.php" method="post">
<input type="text" size="16" name="url" value="输入网址" onfocus="if(this.value=='输入网址'){this.value='';}" onblur="if(this.value==''){this.value='输入网址'};">
<input type="submit" value=" 生成 " />
</form>
</body>
</html>
<?php
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<=35){
$s = chr($s + 55);
} www.jb51.net
$show .= $s;
$x = floor($x/62);
}
return $show;
}
//生成短网址
function url_short($url){
$url = crc32($url);
$result = sprintf("%u",$url);
return base62($result);
}
echo ("生成短网址为:<a href='http://$_POST[url]'>".url_short($_POST['url'])."</a>");
复制代码 代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>urlShort</title>
</head>
<body>
<form action="urlShort.php" method="post">
<input type="text" size="16" name="url" value="输入网址" onfocus="if(this.value=='输入网址'){this.value='';}" onblur="if(this.value==''){this.value='输入网址'};">
<input type="submit" value=" 生成 " />
</form>
</body>
</html>
<?php
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<=35){
$s = chr($s + 55);
} www.jb51.net
$show .= $s;
$x = floor($x/62);
}
return $show;
}
//生成短网址
function url_short($url){
$url = crc32($url);
$result = sprintf("%u",$url);
return base62($result);
}
echo ("生成短网址为:<a href='http://$_POST[url]'>".url_short($_POST['url'])."</a>");
标签:
php,短网址
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“一个php短网址的生成代码(仿微博短网址)”评论...