PHP Classes

PHP Number to Text Converter: Encode and decode numbers using character mappings

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 348 All time: 7,018 This week: 673Up
Version License PHP version Categories
number-converter 1.0GNU General Publi...5.4PHP 5, Text processing, Math
Description 

Author

This class can encode and decode numbers using character mappings.

It can take a given number and encode it using a given list of characters to map the number.

The numbers may be encoded using pre-defined characters sets like upper or lower case letters, digits including 0 or not, and underscore or dash symbols. A custom list of characters may also be included.

The class can also do the opposite, i.e. take a previously encoded number with given character sets and decode the original number.

The class uses arbitrary precision math to allow for very long numbers to be converted.

Innovation Award
PHP Programming Innovation award nominee
August 2015
Number 13
One way to store large numbers with less digits is to represent than in a base higher than 10.

This means that it would use other characters besides 0 to 9 to represent the number in higher base.

This class can convert decimal numbers to be encoded with custom lists of characters to represent their "digits".

It uses arbitrary precision math, so it can represent arbitrary long decimal numbers with much less characters.

Manuel Lemos
Picture of Ivan Gontarenko
  Performance   Level  
Name: Ivan Gontarenko <contact>
Classes: 1 package by
Country: Ukraine Ukraine
Innovation award
Innovation award
Nominee: 1x

Example

<?php

   
use Utils\NumConverter;

    include_once
'./NumConverter.php';

   
$converter = new NumConverter(
       
NumConverter::USE_NUMS_WO_ZERO |
       
NumConverter::USE_LOWERCASE |
       
NumConverter::USE_UPPERCASE
   
);

   
$converter->addCustom( [
       
'_', '-', '%', '@', '+', '=', '!', ':', '~', ';', '(', ')', '^', '#', '[', ']', '{', '}'
   
] );

   
$number = bcmul( PHP_INT_MAX, 7 ); // 64563604257983430649

   
$encoded = $converter->encode( $number ); // 7@U1k6k6^-S

   
$decoded = $converter->decode( $encoded ); // 64563604257983430649

   
var_dump( $number, $encoded, $decoded ); die;


  Files folder image Files (2)  
File Role Description
Accessible without login Plain text file example.php Example Example usage NumConverter class
Plain text file NumConverter.php Class NumConverter PHP class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:348
This week:0
All time:7,018
This week:673Up