|
復(fù)制代碼 代碼如下:
<!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="輸入網(wǎng)址" onfocus="if(this.value=='輸入網(wǎng)址'){this.value='';}" onblur="if(this.value==''){this.value='輸入網(wǎng)址'};">
<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.jbxue.com
$show .= $s;
$x = floor($x/62);
}
return $show;
}
//生成短網(wǎng)址
function url_short($url){
$url = crc32($url);
$result = sprintf("%u",$url);
return base62($result);
}
echo ("生成短網(wǎng)址為:<a href='http://$_POST[url]'>".url_short($_POST['url'])."</a>");
php技術(shù):一個php短網(wǎng)址的生成代碼(仿微博短網(wǎng)址),轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。