您的位置:首页 > 编程语言 > PHP开发

php 生成短网址

2011-10-20 13:37 169 查看
<?php

function base62($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 urlShort($url)

{

$url = crc32($url);

$result = sprintf("%u", $url);

return base62($result);

}

echo urlShort("http://code.google.com/p/rfphp4zf");

原文地址:http://www.oschina.net/code/snippet_106025_6651
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: