ngubin / key-n

Generating a unique short key from the number.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KeyN

Generating a unique short key from the number.

A simple library for converting a number into a string key and back. You can use to shorten long numbers to unique keys.

Latest Version Total Downloads

Example Usage

Creating a key from a number:

You can only encode an integer greater than or equal to one.

use KeyN\Make\Key62;

$instance = Key62::make();
$key = $instance->encode(100000);

Set your own character set to create keys:

use KeyN\Make\Key62;

$characters = 'wWpJbH8nIDed1Evq5OcToF2ZuXsayz7RrtP490ixSKC3GM6gYkNVhBUQmLlfAj';

$instance = Key62::make($characters);
$key = $instance->encode(100000);

Getting the number from the key:

You can decode the key if all of its characters are in the class set.

use KeyN\Make\Key62;

$instance = Key62::make();
$number = $instance->decode('Gh1a');

License

This project is released under the MIT License.

© 2020 Nik Gubin, All rights reserved.

About

Generating a unique short key from the number.

License:MIT License


Languages

Language:PHP 100.0%