日期:2011-12-12  浏览次数:20448 次

  1. <?php 
  2. function base62($x
  3.     $show = ''
  4.     while($x > 0) { 
  5.         $s = $x % 62; 
  6.         if ($s > 35) { 
  7.             $s = chr($s+61);             
  8.         } elseif ($s > 9 && $s <=35) { 
  9.             $s = chr($s + 55); 
  10.         } 
  11.         $show .= $s
  12.         $x = floor($x/62); 
  13.     } 
  14.     return $show;     
  15.  
  16. function urlShort($url
  17.     $url = crc32($url); 
  18.     $result = sprintf("%u"$url); 
  19.     return base62($result); 
  20.  
  21. echo urlShort("http://code.google.com/p/rfphp4zf");