仿微博php生成短网址

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/budinger/article/details/6934828

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="输入网址" οnfοcus="if(this.value=='输入网址'){this.value='';}" οnblur="if(this.value==''){this.value='输入网址'};">
  	<input type="submit" value=" 生成 " />
  </form>
</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;
	}
	
	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>");
	
	

	


展开阅读全文

没有更多推荐了,返回首页