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

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