Home > Backend Development > PHP Tutorial > PHP Weibo short URL algorithm PHP generates short URL implementation code

PHP Weibo short URL algorithm PHP generates short URL implementation code

WBOY
Release: 2016-07-25 08:54:45
Original
1040 people have browsed it
  1. //php生成短网址

  2. function code62($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 shorturl($url) {
  17. $url = crc32($url);
  18. $result = sprintf("%u", $url);
  19. //return $url;
  20. //return $result;
  21. return code62($result);
  22. }

  23. echo shorturl("http://bbs.it-home.org/tags/phpduanwangzhi.html");

  24. ?>

复制代码


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