Share a PHP short URL to generate code.
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8"/>
<title>urlShort</title>
<body>
<form action= "urlshort.php" method= "POST" >
<input type= "text" size= "name=" url "value=" Input url "onfocus=" if (this.value== ' input URL ') {this.value= ';} ' onblur= ' if ( this.value== ') {this.value= ' Enter URL '}; >
<input type= "Submit" value= "Generate"/>
</form>
</body>
<?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;
}
Generate a short URL
function Url_short ($url) {
$url = CRC32 ($url);
$result = sprintf ("%u", $url);
Return base62 ($result);
}
Echo ("Generate a short URL: <a href= ' http://$_post[url] ' >". Url_short ($_post[' url '). " </a> ");