php 生成短URL的算法
2016-01-12 11:02
661 查看
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 code62($result);
}
$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 code62($result);
}
相关文章推荐
- 1.php多态
- mvc中的OutputCache
- php连接ftp
- php获取server端mac和clientmac的地址
- Yii 多表关联relations,需要与with()方法联合使用
- php中计算学生位置代码片段
- FusionCharts在PHP开发中的使用
- yii操作数据库(PDO)
- 命令行cli使用php的exec可以正常,浏览器访问无输出解决方案
- yii操作数据库(AR)
- laravel中遇到的问题
- PHP加密与解密
- [转]TFTP协议详解
- win8.1右键新建菜单添加新建php文件
- tp upload
- 同样遇到PHP 连接SQL2008 查询出现中文乱码问题
- WindowManager.LayoutParams全解
- PHP原生--$_FILES[]['type']的类型
- PHP 类自动加载
- php设计模式详解