PHP生成短连接的方法


PHP生成短连接的方法.md

PHP生成短连接的方法

直接贴上方法,函数可以查看手册。


<?php
/** 生成短网址 
 * @param  String $url 原网址 
 * @return String 
 */  
function dwz($url){  
    $code=floatval(sprintf('%u', crc32($url)));  
    $surl='';  
    while($code){  
      $mod=fmod($code, 62);  
      if($mod>9 && $mod<35){  
        $mod=chr($mod + 61);  
      }  
      $surl .= $mod;  
      $code = floor($code/62);  
    }  
    return $surl;  
}  

//test
echo dwz('http://www.zyall.com');

posted @ 2018-12-30 19:53  lovollll  阅读(197)  评论(0编辑  收藏  举报