PHP Classes

PHP IP Sorter: Sort an array of IP addresses

Recommend this page to a friend!
  Info   View files Example   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
StarStar 34%Total: 309 This week: 1All time: 7,327 This week: 560Up
Version License PHP version Categories
sorterip 1.0GNU General Publi...3.0Networking, Algorithms, PHP 5
Description 

Author

This class can sort an array of IP addresses.

It takes a list of IP v4 addresses and sorts them considering the numbers of its parts separated by dots starting from the first part number.

The class returns the same array with the address elements already sorted.

The sorting algorithm may be overridden providing a callback function to implement a different algorithm.

Innovation Award
PHP Programming Innovation award nominee
September 2014
Number 5


Prize: One downloadable copy of Komodo IDE
Some applications need to group IP addresses according to the networks they belong.

One solution for this problem is to sort the list of IP addresses, so addresses of the same network appear in the list together.

This class can sort a list of IP addresses considering the values of each part of the whole IP address.

Manuel Lemos
Picture of Luca Pacchiarotta
  Performance   Level  
Name: Luca Pacchiarotta is available for providing paid consulting. Contact Luca Pacchiarotta .
Classes: 1 package by
Country: Italy Italy
Age: ???
All time rank: 3809153 in Italy Italy
Week rank: 416 Up16 in Italy Italy Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php

//
// +---------------------------------------------+
// | SORTER IP | V1.0 |
// | http://www.SysTurn.com |
// +---------------------------------------------+
//
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//

include_once ('SorterIp.php');

$ip1 = array('ip' => '192.168.10.1');
$ip2 = array('ip' => '192.168.10.10');
$ip3 = array('ip' => '10.0.0.10');
$ip4 = array('ip' => '10.0.0.5');
$ip5 = array('ip' => '176.10.0.90');
$ip6 = array('ip' => '176.18.10.1');
$ip7 = array('ip' => '132.18.19.128');

$list = array();
$i = 0;
for (
$i = 1; $i < 8; $i++) {
   
$var = "ip$i";
   
$list[$i] = $$var;
}

$objSorter = new SorterIP();
$data = $objSorter -> sort($list);
var_dump($data);

?>


Details

+-------------------------------------+ | Sorter IP | v 1.0 | +-------------------------------------+ Sorter IP It's a PHP class to sort a list of IP addresses. Luca Pacchiarotta luca450mhz at inwind dot it

  Files folder image Files  
File Role Description
Accessible without login Plain text file demo.php Example A demo script
Accessible without login Plain text file license.txt Lic. License
Accessible without login Plain text file readme.txt Data Readme
Plain text file SorterIP.php Class The primary class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:309
This week:1
All time:7,327
This week:560Up
User Ratings User Comments (1)
 All time
Utility:41%StarStarStar
Consistency:50%StarStarStar
Documentation:-
Examples:83%StarStarStarStarStar
Tests:-
Videos:-
Overall:34%StarStar
Rank:4124
 
$tmp1 = explode('.
9 years ago (Dima Zan)
5%Star