Home > Backend Development > PHP Tutorial > 哪位高手能给个关于base62解码的例子?

哪位高手能给个关于base62解码的例子?

WBOY
Release: 2016-06-13 12:54:58
Original
1020 people have browsed it

谁能给个关于base62解码的例子??
在网上看到一个关于网址编码的例子,但是没有解码的例子,有谁给个解码的来看看啊??

给的编码的例子代码:

<?php<br />
function base62($x){<br />
$show = '';<br />
while($x > 0){<br />
$s = $x % 62;<br />
if ($s > 35) {<br />
$s = chr($s+61);<br />
} elseif ($s > 9 && $s<=35) {<br />
$s = chr($s + 55);<br />
}<br />
$show .= $s;<br />
$x = floor($x/62);<br />
}<br />
return $show;<br />
}<br />
function urlShort($url)<br />
{<br />
$url = crc32($url);<br />
$result = sprintf("%u", $url);<br />
return base62($result);<br />
}<br />
echo urlShort("http://www.baidu.com");<br />
?>
Copy after login

php url function
------解决方案--------------------
这是不可能的!
你的 urlShort 函数只取传入数据的校验和(CRC32),因此是不可逆的

------解决方案--------------------
301 跳转
------解决方案--------------------
引用:
引用:这是不可能的!
你的 urlShort 函数只取传入数据的校验和(CRC32),因此是不可逆的

原来如此,那么像那些短网址是如何实现的呢?

以某种算法将域名换算成短域名后入库
根据短域名查表得到原来的域名后跳转
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template