semiorbit/serial

Generate a Serial Number of alphanumeric 16 random chars in PHP.

1.0.3 2023-09-24 23:51 UTC

This package is auto-updated.

Last update: 2024-08-25 02:01:27 UTC


README

Semiorbit Serial Number Generator is a PHP library to create a Serial Number of alphanumeric 16 random chars. It is mostly unique, depending on microtime() and mt_rand() functions converted to BASE 36. (So, it should be 100% unique for one server host as long as server time is accurate and not backward).

Install

composer require semiorbit/serial

Documentation

SerialNumber::Generate

Generates an alphanumeric 16 chars Serial Number. Chars could be grouped in 4 seperated segments.

SerialNumber::Generate(string $separator = '') : string

Params

  • string $separator dash by default
  • returns string
use SemiorbitSerial\Serial;

echo SerialNumber::Generate();

echo SerialNumber::Generate('-');

// OUTPUT:

// CVPKRIJ48NZS4JRO
// CVPK-RIJ4-8NZS-4JRO

SerialNumber::Format

Returns a formatted Serial Number string width dashes (or selected separator)

SerialNumber::Format(string $serial, string $separator = '-'): string

Params

  • string $serial A Serial Number string to parse
  • string $separator Dash by default
  • returns string {xxxx-xxxx-xxxx-xxxx}
use SemiorbitSerial\Serial;

$serial = '4F93820EFEF290A26489E0AE803A37C0';

echo SerialNumber::Format($serial);

// OUTPUT:
// {4F93820E-FEF2-90A2-6489-E0AE803A37C0}

License

The Semiorbit Serial Number is an open-source PHP library licensed under the MIT license.