GitHub - cdoco/hashids.phpc: A php extension for Hashids: generate short unique...
source link: https://github.com/cdoco/hashids.phpc
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
A php extension for Hashids
Requirement
- PHP 7 +
Install
$ git clone https://github.com/cdoco/hashids.phpc.git $ cd hashids.phpc $ phpize && ./configure && make && make install
you can set some options in php.ini, or set in the constructor. i suggest you in php.ini setting, so you will get better performance.
[hashids] extension=hashids.so //default is empty hashids.salt=cdoco //default: 0 hashids.min_hash_length=20 //default: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 //you can use to set it according to your own, for example, is set to all lowercase hashids.alphabet=abcdefghijklmnopqrstuvwxyz
Quick Example
$hashids = new Hashids(); $hash = $hashids->encode(1, 2, 3, 4, 5); // ADf9h9i0sQ $numbers = $hashids->decode($hash); // [1, 2, 3, 4, 5] //or would you prefer to use a static method call $hash = Hashids::encode(1, 2, 3, 4, 5); // ADf9h9i0sQ $numbers = Hashids::decode($hash); // [1, 2, 3, 4, 5]
Performance
php extension and only php code performance contrast.
Other
$hashids = new Hashids(); $hash = $hashids->encode(1, 2, 3, 4, 5); // ADf9h9i0sQ $hash = $hashids->encode([1, 2, 3, 4, 5]); // ADf9h9i0sQ
construct parameter.
new Hashids(string $salt, int $min_hash_length, string $alphabet); //example new Hashids("this is salt.", 20, 'abcdefghijklmnopqrstuvwxyz');
hex.
$hashids = new Hashids(); $hash = $hashids->encodeHex('FFFFDD'); // rYKPAK $hex = $hashids->decodeHex($hash); // FFFFDD
Curses! #$%@
This code was written with the intent of placing created ids in visible places, like the URL. Therefore, the algorithm tries to avoid generating most common English curse words by generating ids that never have the following letters next to each other:
c, f, h, i, s, t, u
License
MIT License. See the LICENSE file. You can use Hashids in open source projects and commercial products. Don't break the Internet. Kthxbye.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK