php微博短网址算法php生成短网址的实现代码
时间:2021-07-01 10:21:17
帮助过:26人阅读
//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("http://bbs.it-home.org/tags/phpduanwangzhi.html"); - ?>
|