Home  >  Article  >  php教程  >  php生成微博短网址的算法

php生成微博短网址的算法

PHP中文网
PHP中文网Original
2016-05-25 17:04:291147browse

php代码

<?php
function code62($x) {
	$show = &#39;&#39;;
	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("此处为网址");
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn