2017 © Pedro PelΓ‘ez
 

library alpha-increment

A library to generate a really unique string from just a classic auto-incremental numeric id.

image

seb-c/alpha-increment

A library to generate a really unique string from just a classic auto-incremental numeric id.

  • Saturday, November 19, 2016
  • by Seb-C
  • Repository
  • 1 Watchers
  • 1 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 11 % Grown

The README.md

AlphaIncrement is a simple library that allows you to generate really unique strings from an incremental id., (*1)

This does not aim to be cryptographically secure nor to be used for security purposes., (*2)

This is useful if you need an easy way to get some kind of unique serial number without especially needing to hide the original id., (*3)

As you can see below, there is still some kind of pattern in the results that an end-user may guess, but it shouldn't be a problem in most cases., (*4)

Basic use

$ai = new AlphaIncrement();
echo $ai->encode(1); // prints "TKSAC"
echo $ai->encode(2); // prints "TKSAD"
echo $ai->encode(3); // prints "TKSAZ"
echo $ai->encode(42); // prints "TKSKY"
echo $ai->encode(314); // prints "TKSGB"
echo $ai->encode(7654321); // prints "9JXCC"

Advanced use

You can pass three arguments to the constructor : - The length of the result string (default: 5); - The alphabet (list of chars to use, as a string). Default: digits and uppercase letters. Unicode characters are supported; - You can pass false here to disable the alphabet shuffling, which is used by default to improve randomization of the results., (*5)

$ai = new AlphaIncrement(4, 'πŸ˜€πŸ˜ƒπŸ˜‰πŸ˜‹πŸ˜ŽπŸ˜΄πŸ˜•πŸ˜“πŸ˜žπŸ˜‡', false);
echo $ai->encode(1); // prints "πŸ˜‹πŸ˜žπŸ˜‰πŸ˜΄"
echo $ai->encode(2); // prints "πŸ˜‹πŸ˜žπŸ˜‰πŸ˜•"
echo $ai->encode(3); // prints "πŸ˜‹πŸ˜žπŸ˜‰πŸ˜“"
echo $ai->encode(42); // prints "πŸ˜‹πŸ˜žπŸ˜‰πŸ˜ž"
echo $ai->encode(314); // prints "πŸ˜‹πŸ˜žπŸ˜‰πŸ˜‡"
echo $ai->encode(654321); // prints "πŸ˜‹πŸ˜žπŸ˜‰πŸ˜€"

Big numbers

Of course you can't fit an infinite amount of ids in a size limited string. The way to fallback from an id too large to fit in the specified size is to make a string larger that the expected size, (*6)

$ai = new AlphaIncrement(3);
echo $ai->encode(10); // returns "SAT"
echo $ai->encode(42); // returns "SKY"
echo $ai->encode(7654321); // returns "9JXCC"
echo $ai->encode(PHP_INT_MAX); // returns "1UL1RDNFPP5OW"

The Versions

19/11 2016

dev-master

9999999-dev

A library to generate a really unique string from just a classic auto-incremental numeric id.

  Sources   Download

The Requires

  • php >=5.6

 

The Development Requires

by SΓ©bastien Caparros

19/11 2016

1.0.0

1.0.0.0

A library to generate a really unique string from just a classic auto-incremental numeric id.

  Sources   Download

The Requires

  • php >=5.6

 

The Development Requires

by SΓ©bastien Caparros