2017 © Pedro Peláez
 

library bijective

Simple bijective function (base(n) encode/decode) for PHP.

image

eric-chau/bijective

Simple bijective function (base(n) encode/decode) for PHP.

  • Thursday, February 4, 2016
  • by eric-chau
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,815 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 6 % Grown

The README.md

Jarvis\Math\Bijective

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., (*1)

<?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:, (*2)

  • Bijective default alphabet is abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. You can define your own alphabet by passing it to its constructor.
  • Bijective throws exception if you try to decode unsupported char.
  • Bijective throws 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 Bijective is instance of \LogicException.

The Versions

04/02 2016

dev-master

9999999-dev

Simple bijective function (base(n) encode/decode) for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Eric Chau

04/02 2016

v1.0.0

1.0.0.0

Simple bijective function (base(n) encode/decode) for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Eric Chau