Home >php教程 >php手册 >仿微博php生成短网址,仿微博php

仿微博php生成短网址,仿微博php

WBOY
WBOYOriginal
2016-06-13 08:38:301083browse

仿微博php生成短网址,仿微博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>  

 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>?>

推荐:http://www.cnblogs.com/roucheng/p/3528396.html

Statement:
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