Generation code for an php short web address of mimic microblog short web address
- 2021-06-28 08:58:51
- OfStack
Share the generation code for an php short web address.
<!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=" Enter Web address " onfocus="if(this.value==' Enter Web address '){this.value='';}" onblur="if(this.value==''){this.value=' Enter Web address '};">
<input type="submit" value=" generate " />
</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.ofstack.com
$show .= $s;
$x = floor($x/62);
}
return $show;
}
// Generate Short Web Address
function url_short($url){
$url = crc32($url);
$result = sprintf("%u",$url);
return base62($result);
}
echo (" Generate a short web address for: <a href='http://$_POST[url]'>".url_short($_POST['url'])."</a>");