Home > Backend Development > PHP Tutorial > Generate short URL by imitating Weibo php, imitating Weibo php_PHP tutorial

Generate short URL by imitating Weibo php, imitating Weibo php_PHP tutorial

WBOY
Release: 2016-07-12 08:51:04
Original
956 people have browsed it

Imitate Weibo php to generate a short URL, imitate Weibo php

html code

<span><!</span><span>DOCTYPE html</span><span>></span>  
<span><</span><span>html </span><span>lang</span><span>="en"</span><span>></span>  
<span><</span><span>head</span><span>></span>  
  <span><</span><span>meta </span><span>charset</span><span>="utf-8"</span> <span>/></span>  
  <span><</span><span>title</span><span>></span>urlShort<span></</span><span>title</span><span>></span>  
<span></</span><span>head</span><span>></span>  
  
<span><</span><span>body</span><span>></span>  
  <span><</span><span>form </span><span>action</span><span>="urlShort.php"</span><span> method</span><span>="post"</span><span>></span>  
    <span><</span><span>input </span><span>type</span><span>="text"</span><span> size</span><span>="16"</span><span> name</span><span>="url"</span><span> value</span><span>="输入网址"</span><span> onfocus</span><span>="if(this.value=='输入网址'){this.value='';}"</span><span> onblur</span><span>="if(this.value==''){this.value='输入网址'};"</span><span>></span>  
    <span><</span><span>input </span><span>type</span><span>="submit"</span><span> value</span><span>=" 生成 "</span> <span>/></span>  
  <span></</span><span>form</span><span>></span>  <span><</span><span>a </span><span>href</span><span>="http://hovertree.com"</span><span>></span>何问起<span></</span><span>a</span><span>></span>
<span></</span><span>body</span><span>></span>  
<span></</span><span>html</span><span>></span>  
Copy after login

php code

<?<span>php  
     </span><span>header</span>("Content-Type:text/html;charset=UTF-8"<span>);    
     </span><span>function</span> base62(<span>$x</span><span>){  
        </span><span>$show</span> = ''<span>;  
        </span><span>while</span>(<span>$x</span>>0<span>){  
            </span><span>$s</span> = <span>$x</span> % 62<span>;  
            </span><span>if</span> (<span>$s</span> > 35<span>){  
                </span><span>$s</span> = <span>chr</span>(<span>$s</span> + 61<span>);  
            }</span><span>else</span> <span>if</span> (<span>$s</span> > 5 && <span>$S</span><=35<span>){  
                </span><span>$s</span> = <span>chr</span>(<span>$s</span> + 55<span>);  
            }  
            </span><span>$show</span> .= <span>$s</span><span>;  
            </span><span>$x</span> = <span>floor</span>(<span>$x</span>/62<span>);  
        }  
        </span><span>return</span> <span>$show</span><span>;  
    }  </span><span>/*</span><span> 何问起 hovertree.com </span><span>*/</span>
      
    <span>function</span> url_short(<span>$url</span><span>){  
        </span><span>$url</span> = <span>crc32</span>(<span>$url</span><span>);  
        </span><span>$result</span> = <span>sprintf</span>("%u",<span>$url</span><span>);   
        </span><span>return</span> base62(<span>$result</span><span>);  
    }  
      
    </span><span>echo</span> ("生成的新网址为:<a href='http://<span>$_POST</span>[url]'>".url_short(<span>$_POST</span>['url'])."</a>"<span>);  
</span>?>
Copy after login

Recommended: http://www.cnblogs.com/roucheng/p/3528396.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1132464.htmlTechArticleImitate Weibo php to generate short URL, imitate Weibo php html code! DOCTYPE html html lang ="en" head meta charset ="utf-8" / title urlShort / title / head body form action ="urlShort.php" meth...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template