viernes, 12 de septiembre de 2014

PHP IP Sorter - Ordenar un array de direcciones IP


PHP IP Sorter es una clase PHP que permite ordenar un array cuyos elementos son direcciones IP.

Se necesita una lista de direcciones IP v4 y los clasifica teniendo en cuenta el número de sus partes separadas por puntos a partir de la primera parte.

La clase devuelve un array con los elementos  ya ordenados.

Descargar:  PHP IP Sorter

Entre los archivos descargados viene un script de demostración, demo.php ...

 <?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);

?> 


No hay comentarios: