PHP头条
热点:

征集常用的PHP简单代码


收集常用的PHP简单代码

对于日常工作中整理出来的某些功能做个简单梳理:

?

1. 短链生成算法

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);
}

br( shorturl("http://pai.game.weibo.com/love/") );
br( shorturl("http://www.oschina.net/code/snippet_878945_22499") );

?

www.phpzy.comtrue/phprm/7447.htmlTechArticle征集常用的PHP简单代码 收集常用的PHP简单代码 对于日常工作中整理出来的某些功能做个简单梳理: ? 1. 短链生成算法 function code62($x) {$show = '';while($x > 0) {$s = $x % 62;if ($s > 35) {$s = chr($s+...

相关文章

相关频道:

PHP之友评论

今天推荐