Share the code generated for a php short URL.
Copy codeThe Code is as follows:
<! 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 = "input url" onfocus = "if (this. value = 'enter URL ') {this. value = '';}" onblur = "if (this. value = '') {this. value = 'enter URL '}; ">
<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.jbxue.com
$ 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> ");