Home > Backend Development > PHP Tutorial > php 字符串变短解决办法

php 字符串变短解决办法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:52:14
Original
2100 people have browsed it

php 字符串变短
需求

$str='topics/new?forum_id=PHP';

echo shortUrl($str)  //    输出:js4d8x5d

echo unShortUrl('js4d8x5d')  //还原字符串    输出:topics/new?forum_id=PHP


求  shortUrl 和  unShortUrl 函数
------解决方案--------------------
没给出编码规则,怎么写程序?
------解决方案--------------------
短链接?
hash函数 + hash冲突解决方案 

新浪的短url貌似是在服务器存储的url和id号的对应关系。没有研究过
------解决方案--------------------
仅以计算得出的话,紧缩的空间有限
假定原串不含有中文,则可以用 96 进制表示 0000000 - 1011111
但只能紧缩 1/8

所以短网址都是以查表法实现的,提供的只是表项索引

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