php生成微博短网址的算法
程序员文章站
2022-06-14 19:09:42
...
php代码
<?php function code62($x) { $show = ''; while($x > 0) { $s = $x % 62; if ($s > 35) { $s = chr($s+61); } elseif ($s > 9 && $s <=35) { $s = chr($s + 55); } $show .= $s; $x = floor($x/62); } return $show; } function shorturl($url) { $url = crc32($url); $result = sprintf("%u", $url); //return $url; //return $result; return code62($result); } echo shorturl("此处为网址"); ?>
下一篇: Zend Platform案例应用