Heim  >  Artikel  >  Backend-Entwicklung  >  php 字符串变短

php 字符串变短

WBOY
WBOYOriginal
2016-06-23 14:00:161504Durchsuche

需求

$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号的对应关系。没有研究过

短链接?
hash函数 + hash冲突解决方案 

新浪的短url貌似是在服务器存储的url和id号的对应关系。没有研究过   
恩 短连接, 对应存储太麻烦了~ 也太多     hash这种类型php系统函数  好多,但是都是单向的。 我理想的是crc32  函数8位结果,但是crc32 也不能反

没给出编码规则,怎么写程序?
就是问这个

仅以计算得出的话,紧缩的空间有限
假定原串不含有中文,则可以用 96 进制表示 0000000 - 1011111
但只能紧缩 1/8

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

仅以计算得出的话,紧缩的空间有限
假定原串不含有中文,则可以用 96 进制表示 0000000 - 1011111
但只能紧缩 1/8

所以短网址都是以查表法实现的,提供的只是表项索引
哦~,想学这个网站的url    http://hangzhou.8684.cn/z_d7bc763d

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn