Skip to content

ajepe/base62

Repository files navigation

Build Status

BASE62

Base is a small package that encodes integer to a string and decodes the same string back to an integer, this is can useful in making URL shortening application or generating unique URL slug. It convert the int id to base 62 characters with the encode method and converts it back to an integer with the decode public method.

  • It converts non-negative integer number like 42000000 up to PHP_INT_SIZE of the platform in which the package is being use on into a string like 2Qe7m. The action is reversible.
  • It can also decode the id back from 2Qe7m to 42000000.
  • This is useful in youtube like url or simply using them making url shortening website.

Install

Via Composer

composer require ajepe/base62:0.0.2

Usage

require 'vendor/autoload.php';


$encode = new Base\Encode();
$decode = new Base\Decode();
$encode = $encode->encode(PHP_INT_MAX); //return HXy0p9
$decode = $decode->decode($encode); // return 24815682095
printf('The encode value of %s map directly to %s', $encode, $decode);

README.md, CHANGELOG.md, CONTRIBUTING.md, LICENSE.txt and composer.json

Change log

Please see CHANGELOG for more information what has changed recently.

About

Converts numeric value to base 62

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages