PHP code example of tomcan / subnet-parser

1. Go to this page and download the library: Download tomcan/subnet-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tomcan / subnet-parser example snippets


$parser = new TomCan\SubnetParser\SubnetParser();
// Parse ranges into subnets
$subnets = $parser->parseRanges(['192.168.1.0/24', '192.168.2.0/24', '192.168.0.0/24']);
// Merge subnets
$subnets = $parser->mergeSubnets($subnets);
foreach ($subnets as $subnet) {
    echo 'Network: '.$subnet->network.'/'.$subnet->prefixlenght.PHP_EOL;
}