Home > Backend Development > PHP Tutorial > Generate short URL

Generate short URL

WBOY
Release: 2016-07-25 09:09:02
Original
948 people have browsed it
  1. function base62($x)
  2. {
  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. {
  18. $url = crc32($url);
  19. $result = sprintf("%u", $url);
  20. return base62($result);
  21. }
  22. echo urlShort("http://code.google.com/p/rfphp4zf");
复制代码


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