PHP Classes

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

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 348 This week: 1All time: 7,014 This week: 560Up
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
Age: 33
All time rank: 370359 in Ukraine Ukraine
Week rank: 411 Up8 in Ukraine Ukraine Up
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  
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

 Version Control Unique User Downloads Download Rankings  
 0%
Total:348
This week:1
All time:7,014
This week:560Up