eric-chau/bijective
Composer 安装命令:
composer require eric-chau/bijective
包简介
Simple bijective function (base(n) encode/decode) for PHP.
README 文档
README
Bijective encodes any integer into a base(n) string where n is alphabet's length. It can be very useful if you want to create your own url shortener.
<?php require_once __DIR__ . '/vendor/autoload.php'; $bijective = new \Jarvis\Math\Bijective(); echo $bijective->alphabet(); // print 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' echo $bijective->encode('64'); // print 'bc' echo $bijective->decode('ba'); // print '62' $bijective = new \Jarvis\Math\Bijective('azerty'); echo $bijective->alphabet(); // print 'azerty'
Things you should know:
Bijectivedefault alphabet isabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. You can define your own alphabet by passing it to its constructor.Bijectivethrows exception if you try to decode unsupported char.Bijectivethrows exception if you try to decode string which start by a zero value (the first char of your defined alphabet. Given the bijective with alphabet '!?:;', the zero value is '!').- every exception throws by
Bijectiveis instance of\LogicException.
统计信息
- 总下载量: 2.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-09