Home > php教程 > PHP源码 > body text

一个php短网址的生成代码(仿微博短网址)_php技巧

PHP中文网
Release: 2016-05-23 16:38:55
Original
1217 people have browsed it

这篇文章主要介绍了一个php短网址的生成代码(仿微博短网址),需要的朋友可以参考下

分享一个php短网址的生成代码。

复制代码 代码如下:






urlShort








header("Content-Type:text/html;charset=UTF-8");
function base62($x){
$show = '';
while($x>0){
$s = $x % 62;
if ($s > 35){
$s = chr($s + 61);
}else if ($s > 5 && $S<=35){
$s = chr($s + 55);
} www.jb51.net
$show .= $s;
$x = floor($x/62);
}
return $show;
}
//生成短网址
function url_short($url){
$url = crc32($url);
$result = sprintf("%u",$url);
return base62($result);
}

echo ("生成短网址为:".url_short($_POST['url'])."");

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template