Hashids将整数等数据类型转化为唯一字符串示例代码
代码语言:php
所属分类:加密解密
代码描述:Hashids将整数等数据类型转化为唯一字符串示例代码,不支持空值,支持数字,数组、字符串,可以设定不同的salt
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<?php require("/data/wwwroot/default/lib/php/hashids/Math.php"); require("/data/wwwroot/default/lib/php/hashids/HashidsInterface.php"); require("/data/wwwroot/default/lib/php/hashids/Hashids.php"); //Quick Example use Hashids\Hashids; $hashids = new Hashids('this is my salt'); $id = $hashids->encode(1, 2, 3); echo $id."<br>"; $numbers = $hashids->decode($id); print_r($numbers) ; $hashids = new Hashids(); $hashids->encode(1); //Note: Hashids requires either the BC Math or GMP extension in order to work. $hashids = new Hashids(); $id = $hashids->encode(1, 2, 3); // o2fXhV $numbers = $hashids->decode($id); // [1, 2, 3] //More Options //A few more ways to pass input ids to the encode() function: $hashids = new Hashids(); $hashids->encode(1, 2, 3); // o2fXhV $hashids->encode([1, 2, 3]); // o2fXhV $hashids->encode('1', '2', '3'); // o2fXhV $hashids->encode(['1', '2', '3']); // o2fXhV //Making your output ids unique //Pass a project name to make your output ids unique: $hashids = new Hashids('My Project'); $hashids->encode(1, 2, 3); // Z4UrtW $hashids = new Hashids('My Other Project'); $hashids->encode(1, 2, 3); // gPUasb //Use padding to make your output ids longer //Note that output ids are only padded to fit at least a certain length. It doesn't mean that they will be exactly that length. $hashids = new Hashids(); // no padding $hashids->encode(1); // jR $hashids = new Hashids('', 10); // pad to length 10 $hashids->encode(1); // VolejRejNm //Using a custom alphabet $hashids = new Hashids('', 0, 'abcdefghijklmnopqrst.........完整代码请登录后点击上方下载按钮下载查看
网友评论0