kurl/base62

Simple base 62 encoder/decoder

Installs: 1 357

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 1

Open Issues: 0

Type:project

1.0.0 2014-05-06 11:42 UTC

This package is auto-updated.

Last update: 2024-10-23 21:28:32 UTC


README

Does what it says on the tin. Converts base 10 numbers to base 62 encoded strings and back again. If the GMP extension is installed this will be used. If not the pure PHP implementation will encode/decode the values. Without actually doing any kind of performance tests I can only assume the GMP driver is better/faster/more precise.

While there are other great base 62 encoders in composer, none reflected the gmp_strval implementation preferring to use a dictionary [0-9a-zA-z] whilst GMP uses [0-9A-Za-z].

Installation

Add the following to your composer.json and update/install:

{
    "require": {
        "kurl/base62": "1.0.*"
    }
}

Encode

<?php

use Kurl\Maths\Encode\Base62;

$encoder = new Base62();
echo $encoder->encode(35);

// Z

Decode

<?php

use Kurl\Maths\Encode\Base62;

$encoder = new Base62();
echo $encoder->encode('a');

// 36

Using the pure PHP encoder

If for whatever reason you want to use the pure PHP driver by default:

<?php

use Kurl\Maths\Encode\Driver\PurePhpEncoder;

$encoder = new Base62();
$encoder->setDriver(new PurePhpEncoder());
echo $encoder->encode('a');

// 36

Why "Maths"?

I'm British and that is how we spell it.