Home >Backend Development >PHP Tutorial >Hashid 把整数生成唯一字符串的PHP类库

Hashid 把整数生成唯一字符串的PHP类库

WBOY
WBOYOriginal
2016-06-20 13:02:342124browse

有时候我们需要把url传参中的id变成非1,2,3,4这样规律性的内容,我们可以用到Hashids这个类库。

生成的 id 比较高大上,比较像 Youtube、Youku、Weibo之类的 id 名,比如:XNjkxMTc0MDQ4

$hashids = new Hashids('Your Keys', 12);
$ids = array(1,2,3);
 // 加密
$str = $hashids->encode($ids);
 // 解密
$ids = $hashids->decode($str);

当然,包很全,还有 Composer package、Laravel 4 package、Laravel 5 package、CodeIgniter spark、Symfony bundle、Kohana module、Wordpress plugin、CakePHP component、Silex package、Craft plugin featu等等。

在官网可以找到链接

还支持 JavaScript, Ruby, Python, Java, Scala, PHP, Perl, Swift, Objective-C, C, C++11, Go, Lua, Elixir, ColdFusion, Groovy, Kotlin, Nim, VBA, CoffeeScript and for Node.js & .NET 语言

项目网址:http://hashids.org/php


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