jakoubek / php-recordlocator
一个将整数编码为简短、易读字符串的库。
dev-master
2018-12-30 11:56 UTC
Requires (Dev)
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2024-08-31 00:32:03 UTC
README
一个将整数编码为简短、易读字符串的库。
php-recordlocator 是 Jesse Vincent 的 Perl 模块 Number::RecordLocator 的 PHP 克隆。
RecordLocator 是一个表示整数的字母数字字符串。此库将整数编码为 RecordLocators,并将 RecordLocators 解码回整数。
RecordLocator 比相应的整数更短,更易于阅读和记忆。您可以使用它将数据库中的自增主键编码为用户可读的表示形式。
Best Practical 使用 RecordLocators 来管理他们的基于网络的待办事项列表和任务管理器 Hiveminder。
示例
- 整数 5,325 编码为 RecordLocator 78G。
- 整数 3,512,345 编码为 RecordLocator 5E82T。
这两个 RecordLocators 比它们对应的整数更短。您可以在一个 5 个字符的 RecordLocator 中编码超过 3350 万个整数:最大的 5 个字符 RecordLocator,ZZZZZ,代表整数 33,554,431。
使用 6 个字符,您可以编码超过 10 亿的整数。
用法
// encoding an integer into a RecordLocator string $generator = new RecordLocator; $integer = 5325; $string = $generator->encode($integer); echo $string;
78G
// decoding a RecordLocator string back to an integer $generator = new RecordLocator; $string = '78G'; $integer = $generator->encode($string); echo $integer;
5325
变更日志
1.0.0 - 发布于 2013-03-03
- 初始版本
1.1.0 - 发布于 2018-12-30
- 更新到 PHPUnit 7