PHP Classes

PHP Split Number: Split a long number into an array of smaller parts

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 enough user ratingsTotal: 165 All time: 8,883 This week: 148Up
Version License PHP version Categories
number-splitter-up 0.1GNU General Publi...5.0Algorithms, PHP 5, Text processing, Math
Description 

Author

This class can split a long number into an array of smaller parts.

It takes a number of many digits and splits it into parts so that each part does not exceed a given maximum number size.

The number parts are returned in an array or as a string.

Innovation Award
PHP Programming Innovation award nominee
November 2014
Number 9


Prize: One subscription to the PDF edition of the PHP Architect magazine
Some applications need to show numbers composed by a long series of digits. Often the numbers are split in groups of a smaller number of digits that are easier to ready and copy.

For some applications it is convenient that each group of digits does not show a number above a given limit.

This class can split long numbers into groups of digits on which each group does not exceed a given limit number, so each group may have one more digit or not depending on whether the given limit was already reached or not.

Manuel Lemos
Picture of Anthony Rogers
  Performance   Level  
Name: Anthony Rogers <contact>
Classes: 3 packages by
Country: United Kingdom
Age: 38
All time rank: 59232 in United Kingdom
Week rank: 83 Up2 in United Kingdom Up
Innovation award
Innovation award
Nominee: 1x

Example

<html>
<head>
<title>Test and Example Page for Number Splitter-Upper</title>
<style>
<!--
  .centre{
    text-align: center;
  }
//-->
</style>
</head>
<body>
<h1 class='centre'>Test and Example Page for Number Splitter-Upper</h1>
<?php
 
 
//Require class
 
require_once('number-splitter-upper.php');
 
 
//For now, just random numbers
  //$really_long_inputted_number has to be a string due to a max size on integers
 
$really_long_inputted_number = '87072316419618716160154502113081209718540150034117075017641332';
 
 
//Max size to split up the numbers
 
$inputted_max_number = 87;
 
 
//Makes calling the function several times so much easier
 
$return_type = 'string';
 
$join = ', ';
 
$filter_zeros = true;
 
$remove_zeros = true;
 
 
//Create instance
 
$n = new Number_Splitter_Upper($really_long_inputted_number, $inputted_max_number);
 
?>
<h2>Inputted numbers</h2>
<h3>Really long number to break up</h3>
<p><?php
 
 
echo $really_long_inputted_number;
 
?></p>
<h3>Maximum number size</h3>
<p><?php
 
 
echo $inputted_max_number;
 
?></p>
<h2>Echo the numbers to screen</h2>
<p><?php
 
  $n
->the_numbers( $join, $filter_zeros, $remove_zeros );
 
?></p>
<h2>Return the numbers for php use</h2>
<p><pre>
<?php
 
  print_r
( $n->get_numbers( 'array', $join, $filter_zeros, $remove_zeros ) );
 
?>
</pre></p>
</body>
</html>


  Files folder image Files  
File Role Description
Accessible without login Plain text file index.php Example Test and Example Page
Plain text file number-splitter-upper.php Class Main Class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:165
This week:0
All time:8,883
This week:148Up