码迷,mamicode.com
首页 > Web开发 > 详细

仿微博php生成短网址

时间:2016-06-11 14:30:07      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:

html code

<!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>  <a href="http://hovertree.com">何问起</a>
</body>  
</html>  

 php code

<?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);  
            }  
            $show .= $s;  
            $x = floor($x/62);  
        }  
        return $show;  
    }  /* 何问起 hovertree.com */
      
    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>");  
?>

推荐:http://www.cnblogs.com/roucheng/p/3528396.html

仿微博php生成短网址

标签:

原文地址:http://www.cnblogs.com/roucheng/p/phpurl.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!