2017 © Pedro Peláez
 

library baseconverter

Converts base 10 numbers to any set of characters provided, for example an [a-zA-Z] range.

image

fzaffa/baseconverter

Converts base 10 numbers to any set of characters provided, for example an [a-zA-Z] range.

  • Saturday, August 27, 2016
  • by fzaffa
  • Repository
  • 1 Watchers
  • 2 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

BaseConverter

The purpose of this library is to convert decimal numbers to higher bases represented only by alphabet characters to render them easier to remember and easier on the eyes for permalinks and similar applications., (*1)

Installation

    $ composer require fzaffa/baseconverter
    {
        "require": {
            "fzaffa/baseconverter": "dev-master"
        }
    }

Usage

    use Fzaffa\BaseConverter\BaseConverter;
    use Fzaffa\BaseConverter\ConverterRangeTypes;

    require "vendor/autoload.php"

    $converter = new BaseConverter(ConverterRangeTypes::ALPHA_ULCASE);

    echo $converter->convert(34523) //Outputs: mNV

    echo $converter->convert("mNV") //Outputs: 34523

The convert() method will automatically get the type of the argument, if it is numeric (also a string containing only numbers work) it will convert to a string, if it's a string it will convert to decimal. To force one or the other use convertFromStringToInt or convertFromIntToString., (*2)

The provided ranges are:, (*3)

  • ConverterRangeTypes::ALPHA_LCASE for [a-z]
  • ConverterRangeTypes::ALPHA_UCASE for [A-Z]
  • ConverterRangeTypes::ALPHA_ULCASE for [a-zA-Z]

You can pass in any array of chars that will be used in lieu of their decimal representation (eg. 12 will be the 12th element of the array)., (*4)

Notes

Will add tests soon., (*5)

Todo

  • Handle cases where the target base is less than 10
  • Write unit tests

License

MIT, (*6)

The Versions

27/08 2016

dev-master

9999999-dev

Converts base 10 numbers to any set of characters provided, for example an [a-zA-Z] range.

  Sources   Download

MIT

The Development Requires

by Francesco Zaffaroni